How to Set Secondary Axis(AxisX2) Minimum and Maximum different from Primary Axis(AxisX) in System.Windows.Forms.DataVisualization.Charting

StackOverflow https://stackoverflow.com/questions/22524382

Question

I am trying to plot a Chart in WinForms using System.Windows.Forms.DataVisualization.Charting with different ranges for AxisX and AxisX2,

chartArea1.AxisX.Minimum=0;
chartArea1.AxisX.Maximum=600;
chartArea1.AxisX2.Minimum=0;
chartArea1.AxisX2.Maximum=300;

AxisX Labels range (0-600) is displayed in AxisX2 instead of range (0-300). Please help me to display AxisX2 labels instead of AxisX labels.

Was it helpful?

Solution

I tried and It works for me if I add this line of code:

  private void Form1_Activated(object sender, EventArgs e)
        {  
           //Added some point just for an  example

            chart1.Series["Series1"].Points.AddXY(1, 1);
            chart1.Series["Series1"].Points.AddXY(2, 2);
            chart1.Series["Series1"].Points.AddXY(3, 3);
            chart1.Series["Series1"].XAxisType = System.Windows.Forms.DataVisualization.Charting.AxisType.Secondary;
        }

I checked out in my Form1.Designer.cs I have:

chartArea1.AxisX.Maximum = 600D;
chartArea1.AxisX.Minimum = 0D;
chartArea1.AxisX2.Maximum = 300D;
chartArea1.AxisX2.Minimum = 0D;

This should do the trick.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top