user2945166
user2945166

Reputation: 83

c# chart interval with custom increase option

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

Answers (1)

jdphenix
jdphenix

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:

enter image description here

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:

enter image description here

Upvotes: 2

Related Questions