Mike_Device Mike_Device - 1 year ago 178
C# Question

Remove axis line from chart c#

I want to remove axis line from chart in c#. I want to have only point there. How to do that?

Here is a result

enter image description here

Here is Code:

public ChartBuilder(ref Chart chart, double minValue, double maxValue)
this.chart = chart;

chart.ChartAreas[0].AxisX.Minimum = minValue;
chart.ChartAreas[0].AxisX.Maximum = maxValue;
chart.ChartAreas[0].AxisY.Minimum = minValue;
chart.ChartAreas[0].AxisY.Maximum = maxValue;

chart.ChartAreas[0].AxisX.MinorGrid.Enabled = false;
chart.ChartAreas[0].AxisX.MajorGrid.Enabled = false;
chart.ChartAreas[0].AxisY.MinorGrid.Enabled = false;
chart.ChartAreas[0].AxisY.MajorGrid.Enabled = false;
chart.ChartAreas[0].AxisY.MajorGrid.LineWidth = 0;

chart.ChartAreas[0].AxisX.LabelStyle.Enabled = false;
chart.ChartAreas[0].AxisY.LabelStyle.Enabled = false;

chart.ChartAreas[0].AxisX.Interval = 1;
chart.ChartAreas[0].AxisY.Interval = 1;

chart.ChartAreas[0].AxisX.LineColor = Color.Transparent;
chart.ChartAreas[0].AxisY.LineColor = Color.Transparent;


Answer Source

For some reason neither setting the LineWidth works nor making the LineColor = Color.Transparent, which usually works fine for Chart elements.

But you can set it to have the same Color as the Chart's BackColor:

chart1.ChartAreas[0].AxisX.LineColor = chart1.BackColor;

enter image description here

To remove a few more things you can write this:

chart1.ChartAreas[0].AxisX.MajorGrid.Enabled = false;
chart1.ChartAreas[0].AxisX.MinorGrid.Enabled = false;
chart1.ChartAreas[0].AxisY.MajorGrid.Enabled = false;
chart1.ChartAreas[0].AxisY.MinorGrid.Enabled = false;

And :


However the simplest way is to disable the axes:

chart1.ChartAreas[0].AxisX.Enabled = AxisEnabled.False; 
chart1.ChartAreas[0].AxisY.Enabled = AxisEnabled.False; 

No need to do anything else to the axes, now..

Now there is only the dot to be seen. I don't post a screenshot of that one point.. ;-)

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download