在C#图表控件中将栅格线型设置为短划线

在C#图表控件中将栅格线型设置为短划线,c#,.net,winforms,visual-studio-2012,mschart,C#,.net,Winforms,Visual Studio 2012,Mschart,我试过了 但它不起作用 设置图表控件的完整代码如下。设置LineDashStyle后,网格线变宽 Chart1.ChartAreas[0].AxisX.MajorGrid.LineDashStyle = ChartDashStyle.Dash; Chart1.ChartAreas[0].AxisY.MajorGrid.LineDashStyle = ChartDashStyle.Dash; 这是我得到的图片。“LinshDashStyle”在第一个图中被更新为dash,第二个图在更新之前 尝试

我试过了

但它不起作用

设置图表控件的完整代码如下。设置LineDashStyle后,网格线变宽

Chart1.ChartAreas[0].AxisX.MajorGrid.LineDashStyle = ChartDashStyle.Dash;
Chart1.ChartAreas[0].AxisY.MajorGrid.LineDashStyle = ChartDashStyle.Dash;
这是我得到的图片。“LinshDashStyle”在第一个图中被更新为dash,第二个图在更新之前


尝试将最后一行添加到代码中,并告诉我们结果

Chart1.ChartAreas[0].AxisX.MajorGrid.LineDashStyle = ChartDashStyle.DashDotDot;
Chart1.ChartAreas[0].AxisY.MajorGrid.LineDashStyle = ChartDashStyle.Dash;
Chart1.ChartAreas[0].AxisX.MajorTickMark.Enabled = false;
Chart1.ChartAreas[0].AxisY.MajorTickMark.Enabled = false;
Chart1.ChartAreas[0].AxisX.IntervalAutoMode = IntervalAutoMode.VariableCount;
Chart1.ChartAreas[0].AxisX.MajorGrid.Interval = 3600;
Chart1.ChartAreas[0].AxisX.Interval = 3600;
Chart1.ChartAreas[0].AxisX.Maximum = 3600 * ((int)m / 3600 + 1);
Chart1.ChartAreas[0].AxisX.Minimum = 0;
Chart1.Series.Add("Latitude");
Chart1.ChartAreas[0].AxisX.Title = "Epoch[h]";
Chart1.ChartAreas[0].AxisX.TitleFont = new Font("TimesNewRoman", 10);
Chart1.ChartAreas[0].Position.Width = 45;
Chart1.ChartAreas[0].Position.Height = 30;
Chart1.Series[0].ChartType = SeriesChartType.Line;
Chart1.Series[0].Points.DataBindXY(time,rms_x);  
Chart1.ChartAreas[0].AxisY.Title = "Latitude[m]";
Chart1.ChartAreas[0].AxisY.TitleFont = new Font("TimesNewRoman", 10);
Chart1.ChartAreas[0].AxisX.LabelStyle.IsStaggered = false;

//Chart1.ChartAreas[0].AxisX.LabelStyle.Interval = 1;
Chart1.ChartAreas[0].Name = "Latitude";
Chart1.ChartAreas[0].Position.X = 0;
Chart1.ChartAreas[0].Position.Y = 0;
Chart1.Series[0].ChartArea = "Latitude";

尝试将最后一行添加到代码中,并告诉我们结果

Chart1.ChartAreas[0].AxisX.MajorGrid.LineDashStyle = ChartDashStyle.DashDotDot;
Chart1.ChartAreas[0].AxisY.MajorGrid.LineDashStyle = ChartDashStyle.Dash;
Chart1.ChartAreas[0].AxisX.MajorTickMark.Enabled = false;
Chart1.ChartAreas[0].AxisY.MajorTickMark.Enabled = false;
Chart1.ChartAreas[0].AxisX.IntervalAutoMode = IntervalAutoMode.VariableCount;
Chart1.ChartAreas[0].AxisX.MajorGrid.Interval = 3600;
Chart1.ChartAreas[0].AxisX.Interval = 3600;
Chart1.ChartAreas[0].AxisX.Maximum = 3600 * ((int)m / 3600 + 1);
Chart1.ChartAreas[0].AxisX.Minimum = 0;
Chart1.Series.Add("Latitude");
Chart1.ChartAreas[0].AxisX.Title = "Epoch[h]";
Chart1.ChartAreas[0].AxisX.TitleFont = new Font("TimesNewRoman", 10);
Chart1.ChartAreas[0].Position.Width = 45;
Chart1.ChartAreas[0].Position.Height = 30;
Chart1.Series[0].ChartType = SeriesChartType.Line;
Chart1.Series[0].Points.DataBindXY(time,rms_x);  
Chart1.ChartAreas[0].AxisY.Title = "Latitude[m]";
Chart1.ChartAreas[0].AxisY.TitleFont = new Font("TimesNewRoman", 10);
Chart1.ChartAreas[0].AxisX.LabelStyle.IsStaggered = false;

//Chart1.ChartAreas[0].AxisX.LabelStyle.Interval = 1;
Chart1.ChartAreas[0].Name = "Latitude";
Chart1.ChartAreas[0].Position.X = 0;
Chart1.ChartAreas[0].Position.Y = 0;
Chart1.Series[0].ChartArea = "Latitude";
谢谢你们的回答和评论,我最终发现我把图表传递给一个对象来设置它的属性就是原因


感谢您的回答和评论,我最终发现我将图表传递给一个对象以设置其属性是原因。

您能提供更多信息吗?是否显示任何错误?您何时尝试更新LineDashStyle?是的,网格线变得更宽。我已经发布了完整的代码。前两行中的代码工作正常!如果它不适合您,则必须有其他代码重置它。事实上,它做的正是它应该做的。一定要张贴你得到的图片!你能提供更多的信息吗?是否显示任何错误?您何时尝试更新LineDashStyle?是的,网格线变得更宽。我已经发布了完整的代码。前两行中的代码工作正常!如果它不适合您,则必须有其他代码重置它。事实上,它做的正是它应该做的。一定要张贴你得到的图片!
txt_Report.Text += ts.ReadData(textBox1.Text, isChecked);
txt_Report.Text += ts.DrawGraph(chart1, textBox1.Text, isChecked);