这个示例展示了如何在图表中绘制 系列 时,实现自定义绘制。 要这样做,则应接管 ChartControl.CustomDrawSeries 事件,然后可以使用事件的参数来改变某些绘制参量。

Note注意

对于 WebChartControl,应该接管 WebChartControl.CustomDrawSeries 事件来完成此任务。

C#CopyCode image复制代码
using DevExpress.XtraCharts;
// ...

private void chartControl1_CustomDrawSeries(object sender, 
CustomDrawSeriesEventArgs e) {
   // Find all Bar Series by their view type,
   // and fill them with Aqua color.
   if (e.Series.View is BarSeriesView)
      e.SeriesDrawOptions.Color = Color.Aqua;

   // Find the series by its name, 
   // and change its line style to dash-dot-dot.
   // (Here it's assumed that the series view type is LineSeriesView).
   if (e.Series.Name == "Line Series") 
      ((LineDrawOptions)e.SeriesDrawOptions).LineStyle.DashStyle = 
      DashStyle.DashDotDot;

   // Find all Point Series by the type of its DrawOptions, 
   // and change their marker kind to diamond.
   if (e.SeriesDrawOptions.GetType() == typeof(PointDrawOptions)) 
      ((PointDrawOptions)e.SeriesDrawOptions).Marker.Kind = 
      MarkerKind.Diamond;
}
Visual BasicCopyCode image复制代码
Imports DevExpress.XtraCharts
' ...

Private Sub OnCustomDrawSeries(sender As Object, e As CustomDrawSeriesEventArgs) _
Handles ChartControl1.CustomDrawSeries
   ' Find all Bar Series by their view type, and fill them with Aqua color.
   If TypeOf e.Series.View Is BarSeriesView Then
      e.SeriesDrawOptions.Color = Color.Aqua
   End If

   ' Find the series by its name, and change its line style to dash-dot-dot.
   ' (Here it's assumed that the series view type is LineSeriesView).
   If e.Series.Name = "Line Series" Then
      CType(e.SeriesDrawOptions, LineDrawOptions).LineStyle.DashStyle = DashStyle.DashDotDot
   End If

   ' Find all Point Series by the type of its DrawOptions, 
   ' and change their marker kind to diamond.
   If e.SeriesDrawOptions.GetType() Is GetType(PointDrawOptions) Then
      CType(e.SeriesDrawOptions, PointDrawOptions).Marker.Kind = MarkerKind.Diamond
   End If
End Sub

Expand image参阅