Reverse the direction of line chart

后端 未结 1 797
佛祖请我去吃肉
佛祖请我去吃肉 2021-01-15 12:25

I have tried many things such as setting Right to Left or messing with the IsReversed property for ChartArea but no go. Any advice?

相关标签:
1条回答
  • 2021-01-15 12:58

    If you want to reverse the x-axis all you need to do is

    private void button1_Click(object sender, EventArgs e)
    {
        ChartArea CA = chart1.ChartAreas[0];
        CA.AxisX.IsReversed = true;
    }
    

    Before and after:

    enter image description hereenter image description here

    If you want to keep the y-axis to the left use this:

    private void button2_Click(object sender, EventArgs e)
    {
        ChartArea CA = chart1.ChartAreas[0];
        CA.AxisY2.Enabled = AxisEnabled.True;
        CA.AxisY.Enabled = AxisEnabled.False;
        CA.AxisX.IsReversed = true;
    }
    

    enter image description here

    If, as you comment, you simply want to add DataPoints to the left, you can do so like this:

    Series S = chart1.Series[0];
    DataPoint dp = new DataPoint(dp.XValue, dp.YValues[0]);
    S.Points.Insert(0, dp);
    

    This may be a little slower, but it will work just as well as Adding them at the end. You may want to have a look at this post, where DataPoints are inserted at various spots in the Points collection..

    Note the Points is often accessed like an array but really is of type DataPointCollection so adding and removing and many other operations are readily available.

    One common use is removing Points from the left to create a 'moving' chart like an oscillograph..

    0 讨论(0)
提交回复
热议问题