I have an error about chart columns order

2019-09-02 10:59发布

问题:

       for(chr=0;chr<10;chr++)
     {
      //some definitions and calculations here
       chrisim[chr] = lst.Columns[chr].Text;
       chrdeger[chr] = ((temp1 + temp3) * 100) / chrdeger[chr];
            if (chrisim[chr].Contains("/3")) chart15.Series["1.Çeyrek Net Kârı"].Points.AddXY(chrisim[chr], chrdeger[chr]);
            if (chrisim[chr].Contains("/6")) chart15.Series["2.Çeyrek Net Kârı"].Points.AddXY(chrisim[chr], chrdeger[chr] - temp);
            if (chrisim[chr].Contains("/9")) chart15.Series["3.Çeyrek Net Kârı"].Points.AddXY(chrisim[chr], chrdeger[chr] - temp);
            if (chrisim[chr].Contains("/12")) chart15.Series["4.Çeyrek Net Kârı"].Points.AddXY(chrisim[chr], chrdeger[chr] - temp);

    }

"chrisim" is string array and "chrdeger" is double array.

my problem is, when I write data on chart, it has not order which is my sending. for example when I send one data to chart here is the picture(blue column is "2013/03".

then I am sending the second data(yellow column is "2012/12":

everything is normal so far.

but,

when I send the third data(red column is "2012/09"),

the order of columns is wrong here as you see the third picture.red column should have the right of yellow.

I want to order these as I send data

2013/03,2012/12,2012/09,2012/06,2012/03..

what is the reason of this? and how can I fix this? thanks.

回答1:

Why do you need 4 series? As far as I can understand, you need a list of (x, y) values where x is a date (year/month) and y is a double value. Now once you have this list populated correctly, you should give it as the data source for a series in the chart. Now the column chart will show the values in the increasing order of the year. Is this what you want?

Moreover what i didnt understand is your statement "my problem is, when I write data on chart, it has not order which is my sending." Why should a chart show data in the order that the data points are added. The data points will be shown at their correct position in the 2D space of the chart and not in the order in which they were added to the chart.



标签: c# charts