xtrareports-devexpress-dot-xtrareports-dot-ui-dot-xrchart-390dd599.md
Allows you to draw custom graphics on top of the chart.
Namespace : DevExpress.XtraReports.UI
Assembly : DevExpress.XtraReports.v25.2.dll
NuGet Package : DevExpress.Reporting.Core
public event CustomPaintEventHandler CustomPaint
Public Event CustomPaint As CustomPaintEventHandler
The CustomPaint event's data class is CustomPaintEventArgs. The following properties provide information specific to this event:
| Property | Description |
|---|---|
| Bounds | Gets the bounds of a custom graphic object. |
| DXGraphics | |
| Graphics | Gets the custom graphic object. |
You can handle the CustomPaint event to draw a line or graphical object over the chart rendered from the XRChart control.
The following code snippet draws a text string and a rectangle with rounded corners:
private void Chart_CustomPaint(object sender, CustomPaintEventArgs args) {
GraphicsCache g = (args is DXCustomPaintEventArgs) ? ((DXCustomPaintEventArgs)args).Cache : new GraphicsCache(args.Graphics);
g.DrawString("TEST", new DXFont("Arial", 14), new SolidBrush(DXColor.Red), new Point(100, 60));
g.DrawRoundedRectangle(DXColor.Blue, 1, new Rectangle(50, 50, 150, 50), new CornerRadius(8));
}
Private Sub Chart_CustomPaint(ByVal sender As Object, ByVal args As CustomPaintEventArgs)
Dim g As GraphicsCache = If((TypeOf args Is DXCustomPaintEventArgs), (CType(args, DXCustomPaintEventArgs)).Cache, New GraphicsCache(args.Graphics))
g.DrawString("TEST", New DXFont("Arial", 14), New SolidBrush(DXColor.Red), New Point(100, 60))
g.DrawRoundedRectangle(DXColor.Blue, 1, New Rectangle(50, 50, 150, 50), New CornerRadius(8))
End Sub
You can use the XYDiagram2D.DiagramToPoint or RadarDiagram.DiagramToPoint methods in the CustomPaint event handler to draw custom graphic objects tied to the chart elements (series or series points).
The following code snippet encircles axis values in the chart:
private void Chart_CustomPaint(object sender, CustomPaintEventArgs e) {
XYDiagram diagram = ((XRChart)sender).Diagram as XYDiagram;
int leftInternalValue = Convert.ToInt32(Math.Ceiling(diagram.AxisX.VisualRange.MinValueInternal));
int rightInternalValue = Convert.ToInt32(Math.Floor(diagram.AxisX.VisualRange.MaxValueInternal));
double bottomYValue = (double)diagram.AxisY.VisualRange.MinValue;
for (int i = leftInternalValue; i <= rightInternalValue; i++) {
var axisValue = diagram.AxisX.GetScaleValueFromInternal(i);
Point axisLabelCoordinates = diagram.DiagramToPoint(axisValue.ToString(), bottomYValue).Point;
axisLabelCoordinates.Offset(-10, 5);
e.Graphics.DrawEllipse(Pens.Red, axisLabelCoordinates.X, axisLabelCoordinates.Y, 20, 20);
}
}
Private Sub Chart_CustomPaint(ByVal sender As Object, ByVal e As CustomPaintEventArgs)
Dim diagram As XYDiagram = TryCast((CType(sender, XRChart)).Diagram, XYDiagram)
Dim leftInternalValue As Integer = Convert.ToInt32(Math.Ceiling(diagram.AxisX.VisualRange.MinValueInternal))
Dim rightInternalValue As Integer = Convert.ToInt32(Math.Floor(diagram.AxisX.VisualRange.MaxValueInternal))
Dim bottomYValue As Double = CDbl(diagram.AxisY.VisualRange.MinValue)
For i As Integer = leftInternalValue To rightInternalValue
Dim axisValue = diagram.AxisX.GetScaleValueFromInternal(i)
Dim axisLabelCoordinates As Point = diagram.DiagramToPoint(axisValue.ToString(), bottomYValue).Point
axisLabelCoordinates.Offset(-10, 5)
e.Graphics.DrawEllipse(Pens.Red, axisLabelCoordinates.X, axisLabelCoordinates.Y, 20, 20)
Next
End Sub
Note
The graphics drawn in the CustomPaint event handler will not affect 3D charts.
See Also