3

I am trying to move Main X and Y axes to the point of (0,0), like: Link

I tried to add 4 lines: (-10,0) to (10,0) and (0-10) to (0,10)

Series ttt = new Series("")
{
    ChartType = SeriesChartType.Line,
    Color = Color.Yellow,
    BorderWidth = 5,
    Font = new Font(Font.OriginalFontName, 20, FontStyle.Regular),
};
ttt.Points.AddXY(0,10);
//ttt.Points.AddXY(0, -10);
this.chart1.Series.Add(ttt);

Unfortunately, also the Main X and Y axis moved to -10,-10 like:

The result

Uwe Keim
  • 39,551
  • 56
  • 175
  • 291
user5742600
  • 33
  • 1
  • 7
  • 1
    can't test it right now but how about the Axis.Crossing property? See the Using Crossing Points section here: https://msdn.microsoft.com/en-us/library/dd489216.aspx – ADyson Dec 19 '17 at 11:32

1 Answers1

3

Setting Axis.Crossing does the job. But I'm not sure how to get double arrows on each axis, but the following code gives this effect

Centered axis

ttt.Points.AddXY(0, 10);
ttt.Points.AddXY(10, 0);
ttt.Points.AddXY(0, -10);
ttt.Points.AddXY(-10, 0);
ttt.Points.AddXY(0, 10);

this.chart1.Series.Add(ttt);

chart1.ChartAreas[0].AxisX.Crossing = 0; // <--- These two lines
chart1.ChartAreas[0].AxisY.Crossing = 0;

And you probably also want to set the axis min/max by

chart1.ChartAreas[0].AxisX.Maximum = 15;
chart1.ChartAreas[0].AxisX.Minimum = -15;
chart1.ChartAreas[0].AxisY.Maximum = 15;
chart1.ChartAreas[0].AxisY.Minimum = -15;
zc246
  • 1,514
  • 16
  • 28