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

Note注意

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

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

private void chartControl1_CustomDrawSeriesPoint(object sender, 
CustomDrawSeriesPointEventArgs e) {
   // These changes will be applied to Bar Series only.
   BarDrawOptions drawOptions = e.SeriesDrawOptions as BarDrawOptions;
   if (drawOptions == null)
      return;
    
   // Get the fill options for the series point.
   drawOptions.FillStyle.FillMode = FillMode.Gradient;
   RectangleGradientFillOptions options = 
   drawOptions.FillStyle.Options as RectangleGradientFillOptions;
   if (options == null)
      return;

   // Get the value at the current series point.
   double val = e.SeriesPoint[0];

   // If the value is less than 2.5, then fill the bar with green colors.
   if (val < 2.5) {
      options.Color2 = Color.FromArgb(154, 196, 84);
      drawOptions.Color = Color.FromArgb(81, 137, 3);
      drawOptions.Border.Color = Color.FromArgb(100, 39, 91, 1);
   } 
   // ... if the value is less than 5.5, then fill the bar with yellow colors.
   else if (val < 5.5) {
      options.Color2 = Color.FromArgb(254, 233, 124);
      drawOptions.Color = Color.FromArgb(249, 170, 15);
      drawOptions.Border.Color = Color.FromArgb(60, 165, 73, 5);
   }
   // ... if the value is greater, then fill the bar with red colors.
   else {
      options.Color2 = Color.FromArgb(242, 143, 112);
      drawOptions.Color = Color.FromArgb(199, 57 ,12);
      drawOptions.Border.Color = Color.FromArgb(100, 155, 26, 0);
   }
}
Visual BasicCopyCode image复制代码
Imports DevExpress.XtraCharts
' ...

Private Sub OnCustomDrawSeriesPoint(ByVal sender As Object, _ 
ByVal e As CustomDrawSeriesPointEventArgs) _
Handles chartControl1.CustomDrawSeriesPoint

   ' These changes will be applied to Bar Series only.
   Dim drawOptions = CType(e.SeriesDrawOptions, BarDrawOptions)
   If drawOptions Is Nothing Then
      Return
   End If

   ' Get the fill options for the series point.
   drawOptions.FillStyle.FillMode = FillMode.Gradient
   Dim options = CType(drawOptions.FillStyle.Options, RectangleGradientFillOptions)
   If options Is Nothing Then
      Return
   End If

   ' Get the value at the current series point.
   Dim val As Double = e.SeriesPoint(0)

   ' If the value is less than 2.5, then fill the bar with green colors.
   If val < 2.5 Then
      options.Color2 = Color.FromArgb(154, 196, 84)
      drawOptions.Color = Color.FromArgb(81, 137, 3)
      drawOptions.Border.Color = Color.FromArgb(100, 39, 91, 1)
      ' ... if the value is less than 5.5, then fill the bar with yellow colors.
   Else
      If val < 5.5 Then
         options.Color2 = Color.FromArgb(254, 233, 124)
         drawOptions.Color = Color.FromArgb(249, 170, 15)
         drawOptions.Border.Color = Color.FromArgb(60, 165, 73, 5)
         ' ... if the value is greater, then fill the bar with red colors.
      Else
         options.Color2 = Color.FromArgb(242, 143, 112)
         drawOptions.Color = Color.FromArgb(199, 57, 12)
         drawOptions.Border.Color = Color.FromArgb(100, 155, 26, 0)
      End If
   End If
End Sub

Expand image参阅