ToolTips
RadChart provides support for displaying tooltips when the mouse cursor hovers over the respective series items.
The tooltips are disabled by default but you can enable them by setting the SeriesDefinition.ShowItemToolTips to True. Moreover, you can enable the functionality for one series and disable it for another in the same chart area. Additionally, you can change the default tooltip format by using SeriesDefinition.ItemToolTipFormat property or you can completely customize the tooltip content by using the ChartArea.ItemToolTipOpening and ChartArea.ItemToolTipClosing events.
The example below shows candlestick chart bound to a collection of TradeData objects, where the TradeData object has the following structure:
You can set the ShowItemToolTips property to True declaratively or in the code-behind.
Note that ShowItemToolTips is a property of the SeriesMapping.SeriesDefinition, which means that you can control the tooltips for each series separately.
On the snapshot below you can see the default tooltip for the CandleStick chart type:
The default tooltip depends on the type of the RadChart:
The tooltip for Range charts shows DataPoint.High and DataPoint.Low values.
The tooltip for Stick and Candlestick charts shows DataPoint.High, DataPoint.Low, DataPoint.Open and DataPoint.Close values.
For all the other chart types, DataPoint.YValue is used.
If the default tooltip does not fit your needs, you can use DataPoint.Tooltip to explicitly specify the exact tooltip text for each data series item. Notice that when DataPoint.Tooltip is set, RadChart will ignore the values set for ItemToolTipFormat.
You can also bind to DataPoint.Tooltip property, using SeriesMapping/ItemMapping with DataPointMember set to Tooltip. Below you can see how to bind the tooltip to the Close property of the underlying TradeData object:
And on the snapshot below you can see that the tooltip for each data point is taken directly from the Close property of the underlying TradeData, ignoring the value specified in ItemToolTipFormat.
Formatting the Tooltip
RadChart allows you to use Format Expressions to format the tooltip text. Use the SeriesDefinition.ItemToolTipFormat property to set the tooltip format for each data series. By using format expressions, you can also add some context data in the tooltip text using tokens.
For example, "#OPEN{0.0000}" means that the tooltip will take the value from the DataPoint.Open property and will format the value using "0.000". When the tooltip is shown, the open value will be formatted with four digits after the decimal point: "147.2746".
You can construct more complex tooltips combining several tokens, for example: "Open: #OPEN{C4}/Close: #CLOSE{C4}1 #DATAITEM.Volume{###,###,##0}". This format expression uses three tokens to obtain the values from the underlying DataPoint object's properties Open, Close and DataItem.Volume. For more about #DATAITEM token take a look at Format Expressions.
The snapshot below shows the customized tooltip:
If you need more information about label formatting take a look at the Format Expressions topic.
To be able to show the ToolTip content separated on new line in XAML you should use the hexidecimally encoded value " " to represent the "\n" literal.
Customizing Tooltip Content
Expression formats are useful when the tooltip represents plain text messages. However, as a ContentControl you can completely customize its appearance using the two events exposed by ChartArea:
ChartArea.ItemToolTipOpening - use to define the content of the tooltip.
ChartArea.ItemToolTipClosing - use to clear any resources related to the shown tooltip.
The next example demonstrates how to use StockToolTipControl - a custom user control as a tooltip on a Candlestick chart. As a RadChart.ItemSource, a list of TradeData objects will be used (more about data binding you can find here).
Now, StockToolTipControl has to be created. It will show additional information in a grid:
In the code-behind, there are a few properties - each one is setting the value of the appropriate text box:
You can play with the colors to give the control a better look and feel.The next step is to assign an event handler to the ChartArea.ItemToolTipOpening event:
ItemToolTipOpening event handler has two parameters:
ItemToolTip2D tooltip - the tooltip control to customize.
ItemToolTipEventArgs e - event arguments from where you can take the DataPoint for which the tooltip has to be shown.
The final step is to create a new instance of the StockToolTipControl and to initialize its properties. ItemToolTipEventArgs.DataPoint.DataItem has to be used. It holds the TradingData object associated to this DataPoint:
As you can see, the new instance of StockToolTipControl is created, initialized and set to toolTip.Content:
Check out how a Drill Down Chart is created using customized tooltip.