Tooltip for Telerik Blazor Chart
The Telerik Chart provides a tooltip for its data points. You can have settings specific to each <ChartSeries>, common tooltip settings for all series, or a shared tooltip for all categories.
In this article:
Basics
By default the value of the point will be presented when hovered over.
To enable tooltips for the data points of each individual series:
- Inside the
<ChartSeries>, include the<ChartSeriesTooltip>tag. - Set its
Visibleparameter totrue.
Enable the tooltip for a specific Chart Series
Common Tooltip
The Chart allows you to enable and define common tooltip settings for all series at once. It looks like the individual tooltips (the value of the point will be presented when hovered over), but you declare it only once.
A tooltip set to a specific <ChartSeries> will take precedence over the common tooltip settings.
To enable the same tooltip for all series:
- Inside the
<TelerikChart>, add the<ChartTooltip>. - Set its
Visibleparameter totrue.
Set a Common Tooltip for all series at once
Customization
There are two types of customizations you can do for the tooltips:
- Parameter Settings - lets you alter cosmetic settings such as borders, colors and padding through simple parameters
- Template - lets you control the entire content
Parameter Settings
You can customize the appearance of the individual series tooltip by using:
-
Background- control the background color by applying a CSS color string, including HEX and RGB. By default the it will match the color for the category. -
Color- control the text color by applying a CSS color string, including HEX and RGB. -
Use the Template to take control over what is rendered in the tooltip.
Configuration of the tooltips with applied customization settings
Common Tooltip Settings
In a similar fashion, you can declare these settings in the common tooltip section:
-
Background- control the background color by applying a CSS color string, including HEX and RGB. By default the it will match the color for the category. -
Color- control the text color by applying a CSS color string, including HEX and RGB. -
Opacity- control the opacity of the tooltip. -
Use the Template to take control over what is rendered in the tooltip - the tag name and data it provides is the same as for the specific tooltip, but it affects all series at once.
Template
The Template allows you to take control over the rendering of the tooltip and include additional information to the user.
In the template you can:
-
Use business logic and render HTML
-
Use the
contextparameter that provides information about the current data point.
The available series data point information in the context is:
-
FormattedValue- maps to the default rendering of the tooltip, formatted as a string. -
Use this when the chart's data is bound by Independent Series Binding. You can parse this to a numerical value (
int,double, etc.) in order to apply formatting. Otherwise, use theDataItemto get the value of the point. -
DataItem- provides the data model of the current series item. You need to cast it to the type from your datasource, which needs to be serializable.- If you are using a Date Axis, the
DataItemwill contain the only the aggregated value in the corresponding y-value field, because it is a collection of more than one items. See theCategorybelow for details.
- If you are using a Date Axis, the
-
Category- provides information on the category the data point is located in. You need to cast it to the type in your data source, for exampleDateTime,string,intor another type. TheCategoryparameter is applicable to Categorical Charts.- When using a Date Axis, you can use it, together with the
BaseUnitvalue of the axis, to filter the data source and obtain the actual data items from the data source in case you want to provide extra information about them.
- When using a Date Axis, you can use it, together with the
-
Percentage- applicable to Donut, Pie and Stacked 100% Charts - the percentage value of the current data point from the whole. -
SeriesIndex- provides the index of the<ChartSeries>the data point belongs to. -
SeriesName- bound to theNameparameter of the<ChartSeries>the data point belongs to. -
SeriesColor- shows the RGB color of the Series the data point belongs to. -
CategoryIndex- shows the index of the data point's x-axis category.
Use the Tooltip Template and use the DataItem to get the value of the point and add additional information