Dundas Chart for ASP.NET
Using Events
See Also Send comments on this topic.
Using Dundas Chart > Enterprise Edition Features > Events and Customizations > Using Events



Glossary Item Box

Overview

Enterprise Edition Only Feature.

There are several events available with the enterprise edition that allow for customization of a chart just before it is drawn.

 

These events include:

 

Note
There are also two other events that are available in both the Professional and Enterprise editions - the PostPaint and PrePaint events, which allow for custom drawing before, or after chart elements are drawn.

  

For more information, refer to the topic on Custom Drawing using the Painting Events.

 

Customize Event

This event fires when all data has been added to the chart control, and all chart properties have been set. The most important use of this event is for the adjustment of automatically calculated property values (i.e. properties that have been set to "Auto"). For example, axis Minimum and Maximum properties by default are set to "Auto", which means that just before drawing, the axis will automatically calculate the maximum and minimum scale values by examining the series data. When the Customize event is called, all properties should already be calculated so that the "real" values will be stored instead of "Auto" values.

When changes are made to a chart area (e.g. an axis scale, etc.), then the chart area properties must be recalculated so that the chart is rendered correctly. To recalculate the chart call the ReCalc method after making the chart area modifications.

 

The CustomizeEventHandler exposes the following parameter:

Example

This example demonstrates how to customize the X axis scale.

Visual Basic Copy Code
Imports Dundas.Charting.WebControl
...

' Customize event handler.
Private Sub Chart1_Customize(ByVal chart As Chart) Handles Chart1.Customize
  ' Adjust X axis scale.
  Chart1.ChartAreas("Default").AxisX.Maximum += 1.0
  Chart1.ChartAreas("Default").AxisX.Minimum -= 1.0
  'Now recalculate the Chart.
  Chart1.ChartAreas("Default").ReCalc()
End Sub


C# Copy Code
using Dundas.Charting.WebControl;
  ...
  
// Customize event handler.
private void Chart1_Customize(Chart chart) 
{
   // Adjust X axis scale.
   Chart1.ChartAreas["Default"].AxisX.Maximum += 1;
   Chart1.ChartAreas["Default"].AxisX.Minimum -= 1;
   // Now recalculate the Chart.
   Chart1.ChartAreas["Default"].ReCalc();
}


 

CustomizeLegend Event

If the legend is enabled, a "default" legend item will automatically be generated for each series or data point that has its ShowInLegend property set to True (the default). Pie and sphere charts have data point legend entries, all other chart types have series legend entries. In addition to this, custom legend items can be added to the legend, and by default are appended to the "default" legend items.

 

For more information about legend items, see the topic on Custom and Default Legend Entries.

 

The CustomizeLegend event can be used to:

 

The CustomizeLegendEventHandler exposes the following parameters:

 

Code Samples

Example

This example demonstrates how to customize the automatically generated ("default") legend items.

Visual Basic Copy Code
Imports Dundas.Charting.WebControl
  ...
  
' CustomizeMapAreas event handler.
Private Sub Chart1_CustomizeLegend(ByVal chart As Chart, ByVal e As CustomizeLegendEventArgs) 
Handles Chart1.CustomizeLegend
  ' Add series name to the legend text for MySeries.
  Dim legendItem As LegendItem
  For Each legendItem In e.LegendItems
    If legendItem.SeriesName = "MySeries" Then
      legendItem.Name = "MySeries - " + legendItem.Name
    End If
  Next
 ' Change legend item color to Red for series "Sales".
  For Each legendItem In e.LegendItems
    If legendItem.SeriesName = "Sales" Then
      legendItem.Color = Color.Red
    End If
  Next
End Sub


C# Copy Code
using Dundas.Charting.WebControl;
  ...
      
// CustomizeMapAreas event handler.
private void Chart1_CustomizeLegend(Chart chart, CustomizeLegendEventArgs e)
{
    // Add series name to the legend text for MySeries.
    LegendItem legendItem;
    foreach(legendItem in e.LegendItems)
    {
        if((legendItem.SeriesName == "MySeries"))
        {
            legendItem.Name = ("MySeries - " + legendItem.Name);
        }
    }
    // Change legend item color to Red for series "Sales".
    foreach(legendItem in e.LegendItems)
    {
        if((legendItem.SeriesName == "Sales"))
        {
           legendItem.Color = Color.Red;
        }
    }
}


 

CustomizeMapAreas Event

A chart client-side image map will automatically be generated if a  ToolTip, Href or MapAreaAttributes property of a  DataPoint, Series, LegendItem or StripLine object is set. A "default" map area will be created for each chart element that has one of these properties set, and the shape and coordinates of these map areas will depend on the chart elements they are used for.

"Custom" map areas can also be added to the chart, and unlike the "default" map areas have a user-defined shape and coordinates (for further information concerning client-side image maps and their map areas see the Client-Side Image Maps topic).

The CustomizeMapAreas event can be used to:

 

The CustomizeMapAreasEventHandler exposes the following parameters:

Example

This example demonstrates how to remove all map areas if the tooltip is not set.

Visual Basic Copy Code
Imports Dundas.Charting.WebControl
  ...
  
' CustomizeMapAreas event handler.
Private Sub Chart1_CustomizeMapAreas(ByVal chart As Chart, ByVal e As CustomizeMapAreasEventArgs) 
Handles Chart1.CustomizeMapAreas
  ' Loop through all map areas.
  Dim areaIndex As Integer = 0
  While areaIndex < e.MapAreasItems.Count
    ' Remove areas if there is no tool tip set.
     If e.MapAreasItems(areaIndex).ToolTip = String.Empty Then
       e.MapAreasItems.RemoveAt(areaIndex)
         areaIndex -= 1
    End If
    areaIndex += 1
  End While
End Sub


C# Copy Code
using Dundas.Charting.WebControl;
  ...
  
// CustomizeMapAreas event handler.
private void Chart1_CustomizeMapAreas(Chart chart, CustomizeMapAreasEventArgs e) 
{
    // Loop through all map areas.
    int areaIndex = 0;
    while((areaIndex < e.MapAreasItems.Count))
    {
        // Remove areas if there is no tool tip set.
        if ((e.MapAreasItems(areaIndex).ToolTip == String.Empty))
        {
            e.MapAreasItems.RemoveAt(areaIndex);
            areaIndex--;
        }
        areaIndex++;
    }
}


See Also

Copyright © 2001 - 2009 Dundas Data Visualization, Inc. and others.