1

I need to create a line chart that connects the points vertically like in the image below (image by TaW) as it was rotated. Creating a regular horizontal chart is clear, but I was unable to find a property that would do this. Switching x and y values would obviously keep the connecting style, can I somehow switch the axes themselves?

enter image description here

Uwe Keim
  • 39,551
  • 56
  • 175
  • 291
  • Just what do you mean by 'vertically connecting lines'? There are no vertical lines in the image and it is just a regular LineChart. – TaW Nov 05 '15 at 16:43

1 Answers1

2

One special thing about SeriesChartType.Line is that you can add the DataPoints freely, not just with any Y-Value, but also with any X-Value.

Other chart types need to X-Values to be distinct but the lines can go forth and back as you please and allowing duplicates as well..

This lets us modify the Points at will but, unfortunately you requirements are not clear.

You ask about 'Rotating the Chart' and 'Switching the Axes'.

Now if we switch the axes by exchanging the X-Values and the Y-Values we have not just rotated the chart but mirrored it along a diagonal; the blue series is the original, the orange one is the result from exchanging x for y:

enter image description here

  chart1.Series.Clear();
  chart1.ChartAreas[0].AxisX.Interval = 2;
  Series S1 = chart1.Series.Add("S1");
  Series S2 = chart1.Series.Add("S2");
  S1.ChartType = SeriesChartType.Line;
  S2.ChartType = SeriesChartType.Line;

  Random R = new Random(42);

  for (int i = 0; i < 15; i++)
  {
        int v = R.Next(10);
        S1.Points.AddXY(i, v);
        S2.Points.AddXY(v, i);
  }

To rotate something we need an angle, here 90° or -90° and a rotation center, here probably the origin (0,0).

The mirroring includes a rotation and a flip. The get rid of the flip we can reverse the X-Axis:

chart1.ChartAreas[0].AxisX.IsReversed = true;

enter image description here

Note how the result looks just like the first series was rotated 90° counterclockwise. Also note that the x-axis now counts backwards as is expected.

If you'd rather have the Y-Axis to the left, (which is not what a rotated chart would look like!) so can use this flipping code from the original post the image you showed us came from:

   ChartArea CA = chart1.ChartAreas[0];
   CA.AxisY2.Enabled = AxisEnabled.True;
   CA.AxisY.Enabled = AxisEnabled.False;
   CA.AxisX.IsReversed = true;

enter image description here

This doesn't mean that X- and Y-Axes are really switched, just the resulting graph looks like it..

If that is not what you meant, please do explain yourself more clearly!

Note especially that to 'simply' rotate the original blue lines not in terms of flipping and mirroring you will need to know your rotation center; to test what you want do try to draw it!!

Community
  • 1
  • 1
TaW
  • 53,122
  • 8
  • 69
  • 111