Reputation: 83
I am using C# Chart, and currently have:
mychart.chartAreas[0].AxisX.Minimum=0;
mychart.chartAreas[0].AxisX.Maximum=40;
mychart.chartAreas[0].AxisX.Interval=4;
This works fine, i.e., I get on x-axis 0, 4, 8, 12, etc... But is there a way to do interval to be power of 2 for example? I.e., I would get x-axis 0, 2, 4, 8, 16, etc. Thanks.
Upvotes: 1
Views: 640
Reputation: 15425
You're wanting a logarithmic X axis on powers of 2.
chart1.ChartAreas[0].AxisX.IsLogarithmic = true;
chart1.ChartAreas[0].AxisX.LogarithmBase = 2;
Will generate a chart that renders it's X-axis like:
You can also render a minor grid with decades like you're likely used to seeing on a logarithmic chart, with this:
chart1.ChartAreas[0].AxisX.Minimum = 1;
chart1.ChartAreas[0].AxisX.Maximum = 64;
chart1.ChartAreas[0].AxisX.Interval = 1;
chart1.ChartAreas[0].AxisX.MinorGrid.Enabled = true;
chart1.ChartAreas[0].AxisX.MinorGrid.Interval = 0.1;
chart1.ChartAreas[0].AxisX.MinorGrid.LineDashStyle = ChartDashStyle.Dash;
chart1.ChartAreas[0].AxisX.IsLogarithmic = true;
chart1.ChartAreas[0].AxisX.LogarithmBase = 2;
renders:
Upvotes: 2