Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
113 views
in Technique[技术] by (71.8m points)

c# - Shifting datapoints in line chart

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

question from:https://stackoverflow.com/questions/65661655/shifting-datapoints-in-line-chart

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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(); }

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...