Natasha Natasha - 1 year ago 158
C# Question

How to add right border of grid in Chart contol

enter image description here

Here is my code for setting properties of chart which is attached above:

chart2.ChartAreas[0].CursorX.IsUserEnabled = true;
chart2.ChartAreas[0].CursorX.IsUserSelectionEnabled = true;
chart2.ChartAreas[0].AxisX.ScaleView.Zoomable = true;
chart2.ChartAreas[0].AxisX.Title = "t";
chart2.ChartAreas[0].AxisY.Title = "w(t)";
chart2.ChartAreas[0].AxisX.Minimum = classes[0].First();
chart2.ChartAreas[0].AxisX.Maximum = classes[m - 1].Last();
chart2.ChartAreas[0].AxisX.Interval = delta_t;
chart2.ChartAreas[0].AxisX.LabelStyle.Format = "{0:0.####}";

I need to add right border of grid so that it will be as it is shown below:

enter image description here

Answer Source

The right border is missing since your data don't nicely fit into the area.

There are many ways to fix this.

Here is the simplest one:

chart2.ChartAreas[0].AxisY2.Enabled = AxisEnabled.True;
chart2.ChartAreas[0].AxisY2.LabelStyle.Enabled = false;

This adds a secondary Y-Axis and turns off its labels.

You can style is as needed:

chart2.ChartAreas[0].AxisY2.MajorTickMark.Enabled = false;
chart2.ChartAreas[0].AxisY2.LineWidth = 3;

enter image description here

You could also draw a line or add an annotation but this is by far the easiest solution.

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