wpf-devexpress-dot-xpf-dot-charts-dot-chartcontrol-c3caef7e.md
Occurs before a series point is drawn, when the chart’s content is being drawn.
Namespace : DevExpress.Xpf.Charts
Assembly : DevExpress.Xpf.Charts.v25.2.dll
NuGet Package : DevExpress.Wpf.Charts
public event CustomDrawSeriesPointEventHandler CustomDrawSeriesPoint
Public Event CustomDrawSeriesPoint As CustomDrawSeriesPointEventHandler
The CustomDrawSeriesPoint event's data class is CustomDrawSeriesPointEventArgs. The following properties provide information specific to this event:
| Property | Description |
|---|---|
| DrawOptions | Gets the settings for custom drawing series of different view types. Inherited from CustomDrawSeriesEventArgs. |
| Handled | Gets or sets a value that indicates the present state of the event handling for a routed event as it travels the route. Inherited from RoutedEventArgs. |
| LabelsTexts | Gets the labels texts for the points currently being painted. |
| LabelText | Gets or sets the text of a label for the point currently being painted. |
| LegendText | Gets or sets the Legend’s text for the series whose points are currently being painted. Inherited from CustomDrawSeriesEventArgs. |
| OriginalSource | Gets the original reporting source as determined by pure hit testing, before any possible Source adjustment by a parent class. Inherited from RoutedEventArgs. |
| PercentValue | Returns the portion of the series point’s value within the total value of a series group to which the series point belongs. |
| RoutedEvent | Gets or sets the RoutedEvent associated with this RoutedEventArgs instance. Inherited from RoutedEventArgs. |
| Series | Gets the series whose points are currently being painted. Inherited from CustomDrawSeriesEventArgs. |
| SeriesPoint | Gets the series point currently being painted. |
| Source | Gets or sets a reference to the object that raised the event. Inherited from RoutedEventArgs. |
| TotalValue | Returns the total value of a series group to which the series point belongs. |
The event data class exposes the following methods:
| Method | Description |
|---|---|
| InvokeEventHandler(Delegate, Object) | When overridden in a derived class, provides a way to invoke event handlers in a type-specific way, which can increase efficiency over the base implementation. Inherited from RoutedEventArgs. |
| OnSetSource(Object) | When overridden in a derived class, provides a notification callback entry point whenever the value of the Source property of an instance changes. Inherited from RoutedEventArgs. |
The CustomDrawSeriesPoint event is raised before every series point is painted. The event parameter’s CustomDrawSeriesEventArgs.Series property provides the series whose specific series options are to be determined. The CustomDrawSeriesPointEventArgs.SeriesPoint property provides the series point which provides access to the data that corresponds to the series point being painted. And the CustomDrawSeriesEventArgs.DrawOptions property provides drawing options specific to each series.
The ChartControl.CustomDrawSeries and CustomDrawSeriesPoint events are always raised in the following order.
CustomDrawSeries event for the first series in the chart’s Diagram.Series collection. The first series in the series collection is a Series for which the SeriesCollection.IndexOf method returns 0.CustomDrawSeriesPoint event for all the series points of the first series.CustomDrawSeries event for the second series in the chart’s Diagram.Series collection.CustomDrawSeriesPoint event for all series points of the second series.This example shows how to change the color of each series point according to its values.
In addition, the point labels text is changed to show the color of the current interval (Green, Yellow, or Red).
To accomplish this, it is necessary to invoke the ChartControl.CustomDrawSeriesPoint event and change its drawing options in the CorrectDrawOptions() method.
In this example, you can deactivate the “Custom Draw” option on the stack panel to return to the default appearance of series points.
View Example: Chart for WPF - Create Custom Draw Chart Series Points
<Window x:Class="CustomDrawChart.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:dxc="http://schemas.devexpress.com/winfx/2008/xaml/charts"
xmlns:dxe="http://schemas.devexpress.com/winfx/2008/xaml/editors"
Title="MainWindow" Height="350" Width="525" >
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="100"/>
<ColumnDefinition />
</Grid.ColumnDefinitions>
<StackPanel Grid.Row="0" Grid.Column="0">
<dxe:CheckEdit Name="chbCustomDraw" Content="Custom Draw" IsChecked="True"
Checked="chbCustomDraw_Checked" Unchecked="chbCustomDraw_Unchecked" />
</StackPanel>
<dxc:ChartControl Grid.Row="0" Grid.Column="1" Name="chart"
CustomDrawSeriesPoint="chart_CustomDrawSeriesPoint">
<dxc:XYDiagram2D>
<dxc:XYDiagram2D.AxisY>
<dxc:AxisY2D GridSpacing="1">
<dxc:AxisY2D.Strips>
<dxc:Strip AxisLabelText="High" MinLimit="2" MaxLimit="3"
Brush="#FFFFDBDB" BorderColor="#00BB002F" />
<dxc:Strip AxisLabelText="Middle" MinLimit="1" MaxLimit="2"
Brush="#FFFFF6BF" BorderColor="#00BB002F" />
<dxc:Strip AxisLabelText="Low" MinLimit="0" MaxLimit="1"
Brush="#FFD6F39F" BorderColor="#00BB002F" />
</dxc:AxisY2D.Strips>
<dxc:AxisY2D.Range>
<dxc:AxisRange MinValue="0" MaxValue="3" />
</dxc:AxisY2D.Range>
</dxc:AxisY2D>
</dxc:XYDiagram2D.AxisY>
<dxc:BarSideBySideSeries2D LabelsVisibility="True">
<dxc:SeriesPoint Argument="A" Value="0.3" />
<dxc:SeriesPoint Argument="B" Value="1.2" />
<dxc:SeriesPoint Argument="C" Value="1.7" />
<dxc:SeriesPoint Argument="D" Value="0.8" />
<dxc:SeriesPoint Argument="E" Value="1.9" />
<dxc:SeriesPoint Argument="F" Value="2.8" />
<dxc:SeriesPoint Argument="G" Value="1.3" />
<dxc:SeriesPoint Argument="H" Value="3" />
</dxc:BarSideBySideSeries2D>
</dxc:XYDiagram2D>
</dxc:ChartControl>
</Grid>
</Window>
using System;
using System.Windows;
using System.Windows.Media;
using DevExpress.Xpf.Charts;
namespace CustomDrawChart
{
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
private void chbCustomDraw_Checked(object sender, RoutedEventArgs e)
{
if (chart != null)
chart.UpdateData();
}
private void chbCustomDraw_Unchecked(object sender, RoutedEventArgs e)
{
if (chart != null)
chart.UpdateData();
}
private void chart_CustomDrawSeriesPoint(object sender, CustomDrawSeriesPointEventArgs e)
{
if ((bool)chbCustomDraw.IsChecked)
{
string color = CorrectDrawOptions(e.SeriesPoint.Value, e.DrawOptions);
if (!String.IsNullOrEmpty(color))
e.LabelText = color + ": " + e.LabelText;
}
}
string CorrectDrawOptions(double val, DrawOptions drawOptions)
{
if (drawOptions == null)
return "";
if (val < 1)
{
drawOptions.Color = Color.FromArgb(0xFF, 0x51, 0x89, 0x03);
return "Green";
}
else if (val < 2)
{
drawOptions.Color = Color.FromArgb(0xFF, 0xF9, 0xAA, 0x0F);
return "Yellow";
}
else
{
drawOptions.Color = Color.FromArgb(0xFF, 0xC7, 0x39, 0x0C);
return "Red";
}
}
}
}
Imports Microsoft.VisualBasic
Imports System
Imports System.Windows
Imports System.Windows.Media
Imports DevExpress.Xpf.Charts
Namespace CustomDrawChart
Partial Public Class MainWindow
Inherits Window
Public Sub New()
InitializeComponent()
End Sub
Private Sub chbCustomDraw_Checked(ByVal sender As Object, ByVal e As RoutedEventArgs)
If chart IsNot Nothing Then
chart.UpdateData()
End If
End Sub
Private Sub chbCustomDraw_Unchecked(ByVal sender As Object, ByVal e As RoutedEventArgs)
If chart IsNot Nothing Then
chart.UpdateData()
End If
End Sub
Private Sub chart_CustomDrawSeriesPoint(ByVal sender As Object, ByVal e As CustomDrawSeriesPointEventArgs)
If CBool(chbCustomDraw.IsChecked) Then
Dim color As String = CorrectDrawOptions(e.SeriesPoint.Value, e.DrawOptions)
If (Not String.IsNullOrEmpty(color)) Then
e.LabelText = color & ": " & e.LabelText
End If
End If
End Sub
Private Function CorrectDrawOptions(ByVal val As Double, ByVal drawOptions As DrawOptions) As String
If drawOptions Is Nothing Then
Return ""
End If
If val < 1 Then
drawOptions.Color = Color.FromArgb(&HFF, &H51, &H89, &H03)
Return "Green"
ElseIf val < 2 Then
drawOptions.Color = Color.FromArgb(&HFF, &HF9, &HAA, &H0F)
Return "Yellow"
Else
drawOptions.Color = Color.FromArgb(&HFF, &HC7, &H39, &H0C)
Return "Red"
End If
End Function
End Class
End Namespace
The following code snippet (auto-collected from DevExpress Examples) contains a reference to the CustomDrawSeriesPoint event.
Note
The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.
wpf-charts-custom-draw-chart-series-points/CS/CustomDrawChart/MainWindow.xaml#L17
<dxc:ChartControl Grid.Row="0" Grid.Column="1" Name="chart"
CustomDrawSeriesPoint="chart_CustomDrawSeriesPoint">
<dxc:XYDiagram2D>
#line 17 "..\..\..\MainWindow.xaml"
this.chart.CustomDrawSeriesPoint += new DevExpress.Xpf.Charts.CustomDrawSeriesPointEventHandler(this.chart_CustomDrawSeriesPoint);
#ExternalSource("..\..\..\MainWindow.xaml",17)
AddHandler Me.chart.CustomDrawSeriesPoint, New DevExpress.Xpf.Charts.CustomDrawSeriesPointEventHandler(AddressOf Me.chart_CustomDrawSeriesPoint)
See Also