2

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

Sorry for the lack of info, I figured it would be just a switch somewhere in the Chart properties that I was overlooking. Anyways, I am making a custom chart and right now the lines are going from left to right BUT I need it to go in the reverse direction

need to draw the fricking thing from right to left

I guess another way to put it woudl be how do I add points going from right to left?

nGX
  • 1,038
  • 1
  • 20
  • 40
  • 2
    Please provide a [Minimal, Complete and Verifiable example](http://stackoverflow.com/help/mcve) or at the very least, how you're creating your chart. – adamdc78 Apr 29 '15 at 00:47
  • possible duplicate of [how to change the direction of X-axis label in ms charts](http://stackoverflow.com/questions/6739303/how-to-change-the-direction-of-x-axis-label-in-ms-charts), or possibly http://stackoverflow.com/questions/25736973/c-sharp-winform-mschart-reverse-y-axis – Rufus L Apr 29 '15 at 00:50
  • This is __not a duplicate__ of the linked posts. – TaW Apr 29 '15 at 08:27

1 Answers1

4

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..

Community
  • 1
  • 1
TaW
  • 53,122
  • 8
  • 69
  • 111
  • woah, this is fancy but not exactly what I was looking for. I am just trying to figure out how to add points starting from the right side of the chart area going left. – nGX Apr 29 '15 at 22:56
  • I will try this out a little later today, I'm trying to mimic the Windows task manager performance graph if you needed some context as to what my end goal was. Thanks – nGX Apr 30 '15 at 17:49
  • I thought so after seeing the image. Insert at 0 and when you have more than a limit Remove at Points.Count then..! – TaW Apr 30 '15 at 17:53