2

I have line chart with 10 points in x axis and y axis is variable. That thing what I need is - when I have (for example) points to x=3 it is moving to the end of chart (x=10). But when there are 10 values (x is in the end of chart) I need to remove first datapoint at x=1 and all datapoints shift to left and new value write at position of x=10. I could not figure out how to do that, I have idea but it was working weird. Thanks for some ideas.

It is working in winforms. Here is an image of chart for example: Example

Dufino
  • 33
  • 6
  • What are you targetting: Winforms, WPF, ASP..? YOU should __always__ TAG your questions correctly so one can see it on the questions page! - Very unclear what you want, what you tried and what happens. Assuming MSChart: You can add and remove datapoints any way you like and you can also change x- and y-values any way you like. - Note that for line charts (as opposed to many other types) the actual order determines the look as much as the values! Three points can be connected in more ways than one, after all.. – TaW Jan 11 '21 at 11:35
  • I am sorry, my bad. I editted my post. Is it better now? – Dufino Jan 12 '21 at 06:13
  • Not really. Maybe this is what you want: `Series s = chart1.Series[0]; s.Points.RemoveAt(0); int xmax = (int)s.Points.Max(x => x.XValue); s.Points.AddXY(xmax + 1, rnd.Next(8) + 7); chart1.ChartAreas[0].RecalculateAxesScale();` ? – TaW Jan 12 '21 at 06:30
  • __If__ you have fixed the XAxis.Minimum/Maximum calues: either don't do it or adapt the values! – TaW Jan 12 '21 at 08:25
  • Thank you for your try. I found solution on my own, posted as answer. – Dufino Jan 13 '21 at 14:44

1 Answers1

0

Solution for my problem is here:

i++;

        if(i<11) { Series s = chart1.Series["Mereni"]; s.Points.AddXY(i, Convert.ToDecimal(textBox1.Text)); }


      if( i > 10) { Series s = chart1.Series["Mereni"];
            
            



            DataPoint s1 = new DataPoint(1,s.Points[1].YValues[0]);
            DataPoint s2 = new DataPoint(2, s.Points[2].YValues[0]);
            DataPoint s3 = new DataPoint(3, s.Points[3].YValues[0]);
            DataPoint s4 = new DataPoint(4, s.Points[4].YValues[0]);
            DataPoint s5 = new DataPoint(5, s.Points[5].YValues[0]);
            DataPoint s6 = new DataPoint(6, s.Points[6].YValues[0]);
            DataPoint s7 = new DataPoint(7, s.Points[7].YValues[0]);
            DataPoint s8 = new DataPoint(8, s.Points[8].YValues[0]);
            DataPoint s9 = new DataPoint(9,s.Points[9].YValues[0]);
            s.Points.Clear();


            s.Points.Add(s1);
            s.Points.Add(s2);
            s.Points.Add(s3);
            s.Points.Add(s4);
            s.Points.Add(s5);
            s.Points.Add(s6);
            s.Points.Add(s7);
            s.Points.Add(s8);
            s.Points.Add(s9);
            s.Points.AddXY(10, Convert.ToDecimal(textBox1.Text));



            /*   s.Points.AddXY(10, Convert.ToDecimal(textBox1.Text)); */
            chart1.ChartAreas[0].RecalculateAxesScale(); }
Dufino
  • 33
  • 6