Back to Devexpress

CustomDrawSeriesPointEventArgs Class

corelibraries-devexpress-dot-xtracharts-7a9f5643.md

latest6.3 KB
Original Source

CustomDrawSeriesPointEventArgs Class

Provides data for a chart control’s ChartControl.CustomDrawSeriesPoint (WebChartControl.CustomDrawSeriesPoint) event.

Namespace : DevExpress.XtraCharts

Assembly : DevExpress.XtraCharts.v25.2.dll

NuGet Package : DevExpress.Charts

Declaration

csharp
public class CustomDrawSeriesPointEventArgs :
    CustomDrawSeriesEventArgsBase
vb
Public Class CustomDrawSeriesPointEventArgs
    Inherits CustomDrawSeriesEventArgsBase

CustomDrawSeriesPointEventArgs is the data class for the following events:

LibraryRelated API Members
WinForms ControlsChartControl.CustomDrawSeriesPoint
ASP.NET Web Forms ControlsWebChartControl.CustomDrawSeriesPoint
.NET Reporting ToolsXRChart.CustomDrawSeriesPoint

Remarks

The CustomDrawSeriesPointEventArgs class represents an argument for the ChartControl.CustomDrawSeriesPoint event of a chart control.

An instance of the CustomDrawSeriesPointEventArgs class with appropriate settings is automatically created and passed to the corresponding event’s handler.

Important

Note, that if you change properties of the chart elements that are available only via getters (e.g., CustomDrawSeriesPointEventArgs.SeriesPoint), these changes will not be effected. To make changes that should be effected, use the CustomDrawSeriesEventArgsBase.SeriesDrawOptions property.

Example

This example demonstrates how to implement custom drawing in charts when drawing the series points of charts. To do this you should handle the ChartControl.CustomDrawSeriesPoint event, and then you can change some of the drawing parameters using its event args.

csharp
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);
   }
}
vb
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

Inheritance

Object EventArgs CustomDrawSeriesEventArgsBase CustomDrawSeriesPointEventArgs

See Also

CustomDrawSeriesPointEventArgs Members

DevExpress.XtraCharts Namespace