【问题标题】:How to show the marker points in line graph using c#如何使用c#在折线图中显示标记点
【发布时间】:2015-12-17 07:16:25
【问题描述】:

我在我的应用程序中使用Line graph 并且工作正常。我试图在折线图中绘制标记点,但没有显示标记点。 在折线图标记属性中,我选择了markerSize 为 5,markerStyle 为圆形,MarkerColor 为蓝色。请参阅下面的代码。

 series1.Name = "Series1";
 series1.IsVisibleInLegend = false;
 series1.IsXValueIndexed = true;
 series1.XValueType = ChartValueType.Time;
 series1.YAxisType = AxisType.Primary;
 series1.ChartType = SeriesChartType.Line;
 this.chart1.Series.Add(series1);

【问题讨论】:

    标签: c# winforms data-visualization linegraph


    【解决方案1】:

    我看不出Markers 是如何从您的代码中显示出来的。

    您需要设置一个非默认 MarkerStyle:

     series1.MarkerStyle = MarkerStyle.Circle;
    

    如果您在该行使用 debugger,您可以看到 defaultNone

    当然你会想和所有其他marker relates series properties一起玩,它们都继承自DataPointCustomProperties

    您正在使用ChartType.Line,这很好。注意FastLine 不显示标记!

    如果您只想显示一些标记,只需为每个点设置样式:

    S1.Points[8].MarkerStyle = MarkerStyle.Triangle;
    S1.Points[8].MarkerSize = 22;
    S1.Points[8].MarkerColor = Color.Red;
    

    【讨论】:

      【解决方案2】:

      我建议获取您的每一个点,遍历它们并添加每个点。我注意到你想设置一个名字,所以我只是创建了一个计数器,然后将一个整数值附加到 'ser' 的末尾,你可以随意命名。

      Dim counter as int = 0;
      foreach (Series ser in chart.Series)
      {
         ser.Name = "ser" & counter + 1;
         ser.IsVisibleInLegend = false;
         ser.IsXValueIndexed = true;
         ser.XValueType = ChartValueType.Time;
         ser.YAxisType = AxisType.Primary;
         ser.ChartType = SeriesChartType.Line;
         this.chart1.Series.Add(ser);
         counter += 1;
      }
      

      【讨论】:

      • 我所需要的正是我想在折线图中添加标记点(点),同时将自身绘制到相应的值。
      猜你喜欢
      • 1970-01-01
      • 2012-01-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-02-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多