Chart with horizontal scrolling c#

Asked

Viewed 111 times

1

Good morning guys, I’m drawing a line chart on a pictureBox with "drawline"s concatenated.

Basically what I want is to create a horizontal scroll bar to navigate the chart, that is, to be able to scroll through the chart horizontally using the scroll bar. Follows code drawing graph.

    void DrawANALISE()
    {
        Graphics g = pcbANALISE.CreateGraphics();
        g.SmoothingMode = SmoothingMode.AntiAlias;

        var lastPoint1 = new PointF(0F, (float)(2 * Height / 5) * 0.5F);
        PointF newPoint1 = new PointF();

        for (int i = 0; i < 6000; i++)
        {
            //aquisicaodata é uma lista onde há 6000 valores para y
            var porcent = aquisicaodata[i] / 5;
            newPoint1.X = (i + 1) * 0.2f;

            if (porcent > 1) porcent = 1;
            var hg = porcent * (2 * pcbANALISE.Height / 5);

            if (porcent >= 1) newPoint1.Y = 2 * pcbANALISE.Height / 5 - hg;
            else newPoint1.Y = 2 * pcbANALISE.Height / 5 - hg - 1;

            using (var p = new Pen(Color.Lime, 0.1f)) g.DrawLine(p, lastPoint1, newPoint1);

            lastPoint1 = newPoint1;
        }
    }

Since in the code I am drawing 1 point every 0.2 pixels horizontally and there are a total of 6000 points, which would result in a total of 1200 pixels horizontally to draw whole graph, a pcb of 500 pixels wide is not enough to display whole graph. That is why I would like to create a horizontal scroll bar so that I can have a view of the entire chart. I will edit if necessary. If anyone can help, I’d really appreciate it!

1 answer

2


Just create a control variable for the scrollbar camera:

int camera = 0;

This part would look like this:

for (int i = camera; i < (camera + (pictureBox.Width / 0.2)); i++)

and in the scrollbar event:

hscrollBar_scroll(EventArgs e, object sender)
{
    camera = hScrollBar.Value * 6000 / 100;
    DrawANALISE();//esqueci de por para redesenhar o gráfico.
}

If I can’t help you with that, I can do a full control, if you prefer.

  • Thanks again for the attention Weiner, so friend, I did here this way but did not work scrolling. I move the scrollbar but the graph is still stopped.

  • If you can continue helping I would be very pleased.

  • Just add the method to redesign in the scrollbar, I had forgotten.

  • Friend, it even works the scrolling this way, but the graph is really redesigning from the beginning to each tick of the scrolling, which makes the performance fall a lot, if I click to move the graph the program gets a little stuck.

  • Now do not want to update haha, show the following error: "System.Invalidoperationexception: 'The object is being used elsewhere.".

  • and points to the following line : using (var p = new Pen(Color.Blue, 0.1f)) g.Drawline(p, lastPoint2, newPoint2);

  • I will try to make an Aki control to help you, but really you have the need to draw 10 values in a single pixel, because it is not even being shown all these values.

  • For my application I need 300 points on a second friend

  • is not being shown? Why, if you are not losing performance at all

  • if you can do this check I thank you, tried in several ways but unsuccessfully.

  • Dude, I don’t know if you know how to answer this, but do you know if for a graphical visualization and analysis application, with user interface it would be better to use c# or java? I don’t have much knowledge in the area yet. I believe the two are similar.

Show 6 more comments

Browser other questions tagged

You are not signed in. Login or sign up in order to post.