Tutorial 49: Adding custom text or drawings to chart
« on: February 05, 2016, 01:29:39 AM »
Crossing Charts for .NET exposes 3 events that you can use to add custom content, text or drawings to the chart canvas:
  • BeginPaint: occurs just after clearing the canvas and before any other drawing is done.
  • AfterPaint: occurs when chart is completed, before screen refreshing occurs..
  • ValueClick: occurs when any value item (bar, line, point, ...) is clicked by user.

In this sample, a simple text is added to the chart in the left side ("Custom text added by user").


1. Create a new Windows application project (VB.NET).
2. Add Crossing Charts Library to the toolbox pallete and drag it to Form1.
3. Copy and paste de following code:
Code: [Select]
Imports CrossingChartsLibrary
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  With CrossingCharts1
    .Style = STYLE2D3D.STYLE2D_PIE
  End With
End Sub
Private Sub CrossingCharts1_AfterPaint(ByVal g As CustomGraphics) Handles Super2d3dGraph1.AfterPaint
  g.TranslateTransform(30, -50)
  ' Draw text in white first, displaced 2 pixels, to simulate a glow effect
  g.DrawString("Custom Text Added By User", New Font("Arial", 30), New SolidBrush(Color.White), 0, 0)
  g.DrawString("Custom Text Added By User", New Font("Arial", 30), New SolidBrush(Color.Purple), 2, 2)
End Sub
End Class


« Last Edit: February 16, 2016, 11:20:19 AM by CrossingCharts »