Overview
There are several events available with the enterprise edition that allow for customization of a chart just before it is drawn.
These events include:
- Customize: Adjust the chart settings just before the chart is drawn.
- CustomizeLegend: Customize legend items.
- CustomizeMapAreas: Customize the map areas of an image map.
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:
- Chart: This is the root Chart object that is used to perform the chart customization.
Example
This example demonstrates how to customize the X axis scale.
Visual Basic | Copy Code |
---|---|
|
C# | Copy Code |
---|---|
|
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:
- Remove legend items.
- Change legend items properties.
- Add custom legend items.
- Change the order of custom and default legend items.
The CustomizeLegendEventHandler exposes the following parameters:
- Chart: The root Chart object.
- CustomizeLegendEventArgs: The event arguments. This object exposes the LegendItems collection property which contains all legend items (both default and custom items ), and is used to modify, delete and add legend items. Note that a LegendItem object's SeriesName and SeriesPointIndex properties can be used to identify the series/data point that each default legend item was generated for (these properties will be zero-length strings for custom legend items since they do not correspond to data).
-
Note If you are using the CustomizeLegend event, we advise you to use the Cells collection to modify the contents of a legend item. The Cells collection has a higher priority and provides more flexibility to customize individual cells in a legend item.
Code Samples
Example
This example demonstrates how to customize the automatically generated ("default") legend items.
Visual Basic | Copy Code |
---|---|
|
C# | Copy Code |
---|---|
|
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:
- Remove map areas.
- Change map areas properties.
- Add new custom map areas.
- Change the order of map areas.
The CustomizeMapAreasEventHandler exposes the following parameters:
- ByVal chart As Chart: The root Chart object that will be customized.
- ByVal e As CustomizeMapAreasEventArgs: Event arguments. A MapAreasItems collection property is exposed which contains all default (automatically generated) map areas (i.e. "custom" map areas are not included ). Use this property to delete or modify the default map areas, or add custom map areas.
Example
This example demonstrates how to remove all map areas if the tooltip is not set.
Visual Basic | Copy Code |
---|---|
|
C# | Copy Code |
---|---|
|