【问题标题】:Set grid linetype as dash in C# Chart Control在 C# 图表控件中将网格线型设置为破折号
【发布时间】:2016-06-01 08:44:42
【问题描述】:

我试过了

Chart1.ChartAreas[0].AxisX.MajorGrid.LineDashStyle = ChartDashStyle.Dash;
Chart1.ChartAreas[0].AxisY.MajorGrid.LineDashStyle = ChartDashStyle.Dash;

但不工作。

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

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";

这是我得到的图片。'LinshDashStyle'已更新为第一个图中的破折号,第二个图是更新之前的。

【问题讨论】:

  • 您能提供更多信息吗?是否显示任何错误?您何时尝试更新 LineDashStyle?
  • 是的,网格线变宽了。我已经发布了完整的代码。
  • 前两行的代码运行良好!如果它不适合您,则必须有一些其他代码可以重置它。因为它只是做它应该做的。请张贴您所获得的图片!

标签: c# .net winforms visual-studio-2012 mschart


【解决方案1】:

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

Chart1.ChartAreas[0].AxisX.MajorGrid.LineDashStyle = ChartDashStyle.Dash;
Chart1.ChartAreas[0].AxisY.MajorGrid.LineDashStyle = ChartDashStyle.Dash;
Chart1.ChartAreas[0].BorderDashStyle = ChartDashStyle.Dash;

【讨论】:

    【解决方案2】:
    txt_Report.Text += ts.ReadData(textBox1.Text, isChecked);
    txt_Report.Text += ts.DrawGraph(chart1, textBox1.Text, isChecked);
    

    感谢您的所有回答和 cmets,我终于发现我将 Chart 传递给一个对象以设置其属性是原因。

    【讨论】:

      猜你喜欢
      • 2023-02-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-07-30
      • 1970-01-01
      相关资源
      最近更新 更多