Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Charts grid lines style

Tags:

c#

charts

I am using the standard charts library from Visual Studio 2010. The chart works fine but I am unable to change the axis grid line style. These are the properties already set in Form1.Designers.cs

chartArea3.Name = "ChartArea1";
        this.chart1.ChartAreas.Add(chartArea3);
        legend3.Name = "Legend1";
        this.chart1.Legends.Add(legend3);
        this.chart1.Location = new System.Drawing.Point(12, 68);
        this.chart1.Name = "chart1";
        series5.ChartArea = "ChartArea1";
        series5.ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Line;
        series5.Color = System.Drawing.Color.Red;
        series5.Legend = "Legend1";
        series5.Name = "Temp";
        series6.ChartArea = "ChartArea1";
        series6.ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Line;
        series6.Color = System.Drawing.Color.Blue;
        series6.Legend = "Legend1";
        series6.Name = "Umid";
        this.chart1.Series.Add(series5);
        this.chart1.Series.Add(series6);
        this.chart1.Size = new System.Drawing.Size(647, 182);
        this.chart1.TabIndex = 8;
        this.chart1.Text = "chart1";
        this.chart1.ChartAreas[0].AxisY.Interval=5;

I would like to have the axis grid type dots or dashdots. I have tried with:

this.chart1.ChartAreas[0].AxisX.LineDashStyle.??????

but then I do not know how to assign the property and/or if the above partial line of code is correct.

like image 371
FeliceM Avatar asked Jun 21 '13 15:06

FeliceM


People also ask

How do you format grid lines?

Click the chart, and then click the Chart Design tab. Click Add Chart Element > Gridlines. Choose the axis that you want to apply the gridlines to or click More Gridline Options to open the Format Major Gridlines pane.

How many types of gridlines are there for chart?

Grid lines come in two types: major and minor. Major grid lines separate the axis into major units. On category axes, major grid lines are the only grid lines available (you cannot show minor grid lines on a category axis.) On value axes, major grid lines are drawn for every major axis division.

What are grid lines in a chart?

Grid lines are lines drawn in the chart plot area to 'assist in the visual alignment of data. ' These charts can have vertical grid lines, horizontal grid lines, or both.

How do I format individual grid lines in Excel?

ANSWER: Right click on a gridline, and select format axis. Find the box that says "Horizontal line crosses at:" and enter the value of the gridline you want to format differently than the others [for example, 100 for the graph above].


2 Answers

Finally I got it right:

 this.chart1.ChartAreas[0].AxisX.MajorGrid.LineDashStyle = System.Windows.Forms.DataVisualization.Charting.ChartDashStyle.DashDotDot;
        this.chart1.ChartAreas[0].AxisY.MajorGrid.LineDashStyle = System.Windows.Forms.DataVisualization.Charting.ChartDashStyle.DashDotDot;

This is working and gives access to the line style of the grid axes.

 this.chart1.ChartAreas[0].AxisX.MajorGrid.LineDashStyle = System.Windows.Forms.DataVisualization.Charting.ChartDashStyle.availableStileSelectionHere;
like image 111
FeliceM Avatar answered Sep 24 '22 05:09

FeliceM


You'll want to check out the ChartDashStyle enumeration. Your choices should be Dash, DashDot, DashDotDot, Dot, Solid, and NotSet.

AxisX is of type Charting.Axis so that's where the line type information is expressed.

So try:

this.chart1.ChartAreas[0].AxisX.LineDashStyle.Dot

or

this.chart1.ChartAreas[0].AxisX.LineDashStyle.DashDot
like image 41
John Avatar answered Sep 24 '22 05:09

John