C# 图表网格线样式

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/17239218/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-10 08:55:41  来源:igfitidea点击:

Charts grid lines style

c#charts

提问by FeliceM

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

我正在使用 Visual Studio 2010 的标准图表库。图表工作正常,但我无法更改轴网格线样式。这些是已经在 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.

但是我不知道如何分配属性和/或上面的部分代码行是否正确。

采纳答案by FeliceM

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;

回答by John

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

您需要查看ChartDashStyle枚举。您的选择应该是DashDashDotDashDotDotDotSolid,和NotSet

AxisXis of type Charting.Axisso that's where the line type information is expressed.

AxisX是类型,Charting.Axis所以这是线类型信息被表达的地方。

So try:

所以尝试:

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

or

或者

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