Tooltip in ASP.NET CORE Chart Component

19 Dec 202424 minutes to read

Chart will display details about the points through tooltip, when the mouse is moved over the point.

Enable tooltip

The tooltip is useful when you cannot display information by using the data labels due to space constraints. You can enable the tooltip by setting Enable property as true in Tooltip object.

<ejs-chart id="container">
        <e-chart-tooltipsettings enable="true">
        </e-chart-tooltipsettings>
        <e-chart-legendsettings visible="false"></e-chart-legendsettings>
        <e-chart-primaryxaxis valueType="Category"></e-chart-primaryxaxis>
        <e-series-collection>
            <e-series dataSource="ViewBag.dataSource" name="Germany" xName="x" width="2" opacity="1" yName="yValue" type="@Syncfusion.EJ2.Charts.ChartSeriesType.Column">
            </e-series>
        </e-series-collection>
    </ejs-chart>
public IActionResult Index()
        {
            List<ColumnChartData> chartData = new List<ColumnChartData>
            {
                new ColumnChartData { x= "USA", yValue= 46 }, 
                new ColumnChartData { x= "GBR", yValue= 27 }, 
                new ColumnChartData { x= "CHN", yValue= 26 },
                new ColumnChartData { x= "UK", yValue= 26 },
                new ColumnChartData { x= "AUS", yValue= 26 },
                new ColumnChartData { x= "IND", yValue= 26 },
                new ColumnChartData { x= "DEN", yValue= 26 },
                new ColumnChartData { x= "MEX", yValue= 26 },
            };
            ViewBag.dataSource = chartData;
            return View();
        }
        public class ColumnChartData
        {
            public string x;
            public double yValue;
        }

Fixed tooltip

By default, tooltip track the mouse movement, but you can set a fixed position for the tooltip by using the Location property.

<ejs-chart id="container">
        <e-chart-tooltipsettings enable="true">
            <e-tooltipsettings-location x="120" y="20"></e-tooltipsettings-location>
        </e-chart-tooltipsettings>
        <e-chart-legendsettings visible="false"></e-chart-legendsettings>
        <e-chart-primaryxaxis valueType="Category" interval="1"></e-chart-primaryxaxis>
        <e-series-collection>
            <e-series dataSource="ViewBag.dataSource" name="Gold" xName="xValue" width="2" yName="yValue" type="@Syncfusion.EJ2.Charts.ChartSeriesType.Column">
            </e-series>
        </e-series-collection>
    </ejs-chart>
public IActionResult Index()
{
    List<ColumnChartData> chartData = new List<ColumnChartData>
    {
        new ColumnChartData { xValue= "USA", yValue= 46 }, 
        new ColumnChartData { xValue= "GBR", yValue= 27 }, 
        new ColumnChartData { xValue= "CHN", yValue= 26 },
        new ColumnChartData { xValue= "UK",  yValue= 26 },
        new ColumnChartData { xValue= "AUS", yValue= 26 },
        new ColumnChartData { xValue= "IND", yValue= 26 },
        new ColumnChartData { xValue= "DEN", yValue= 26 },
        new ColumnChartData { xValue= "MEX", yValue= 26 }
    };
    ViewBag.dataSource = chartData;
    return View();
}
public class ColumnChartData
{
    public string xValue;
    public double yValue;
}

Format the tooltip

By default, tooltip shows information of x and y value in points. In addition to that, you can show more information in tooltip. For example the format ${series.name} ${point.x} shows series name and point x value.

<ejs-chart id="container">
        <e-chart-tooltipsettings enable="true" header="Unemployment" format="<b>${point.x} : ${point.y}</b>">
        </e-chart-tooltipsettings>
        <e-chart-legendsettings visible="false"></e-chart-legendsettings>
        <e-chart-primaryxaxis valueType="Category"></e-chart-primaryxaxis>
        <e-series-collection>
            <e-series dataSource="ViewBag.dataSource" name="Germany" xName="x" width="2" opacity="1" yName="yValue" type="@Syncfusion.EJ2.Charts.ChartSeriesType.Column">
            </e-series>
        </e-series-collection>
    </ejs-chart>
public IActionResult Index()
        {
            List<ColumnChartData> chartData = new List<ColumnChartData>
            {
                new ColumnChartData { x= "USA", yValue= 46 }, 
                new ColumnChartData { x= "GBR", yValue= 27 }, 
                new ColumnChartData { x= "CHN", yValue= 26 },
                new ColumnChartData { x= "UK", yValue= 26 },
                new ColumnChartData { x= "AUS", yValue= 26 },
                new ColumnChartData { x= "IND", yValue= 26 },
                new ColumnChartData { x= "DEN", yValue= 26 },
                new ColumnChartData { x= "MEX", yValue= 26 },
            };
            ViewBag.dataSource = chartData;
            return View();
        }
        public class ColumnChartData
        {
            public string x;
            public double yValue;
        }

Tooltip template

Any HTML elements can be displayed in the tooltip by using the Template property of the tooltip. You can use the ${x} and ${y} as place holders in the HTML element to display the x and y values of the corresponding data point.

<ejs-chart id="container">
        <e-chart-tooltipsettings enable="true" template="#Unemployment">
        </e-chart-tooltipsettings>
        <e-chart-legendsettings visible="false"></e-chart-legendsettings>
        <e-chart-primaryxaxis valueType="Category"></e-chart-primaryxaxis>
        <e-series-collection>
            <e-series dataSource="ViewBag.dataSource" name="Germany" xName="x" width="2" opacity="1" yName="yValue" type="@Syncfusion.EJ2.Charts.ChartSeriesType.Column">
            </e-series>
        </e-series-collection>
  </ejs-chart>
  <script id="Unemployment" type="text/x-template">
    <div id='templateWrap'>
        <table style="width:100%;  border: 1px solid black;">
            <tr><th colspan="2" bgcolor="#00FFFF">Unemployment</th></tr>
            <tr><td bgcolor="#00FFFF">${x}:</td><td bgcolor="#00FFFF">${y}</td></tr>
        </table>
    </div>
</script>
public IActionResult Index()
        {
            List<ColumnChartData> chartData = new List<ColumnChartData>
            {
                new ColumnChartData { x= "USA", yValue= 46 },
                new ColumnChartData { x= "GBR", yValue= 27 },
                new ColumnChartData { x= "CHN", yValue= 26 },
                new ColumnChartData { x= "UK", yValue= 26 },
                new ColumnChartData { x= "AUS", yValue= 26 },
                new ColumnChartData { x= "IND", yValue= 26 },
                new ColumnChartData { x= "DEN", yValue= 26 },
                new ColumnChartData { x= "MEX", yValue= 26 },
            };
            ViewBag.dataSource = chartData;
            return View();
        }
        public class ColumnChartData
        {
            public string x;
            public double yValue;
        }

Customize the appearance of tooltip

The Fill and Border properties are used to customize the background color and border of the tooltip respectively. The TextStyle property in the tooltip is used to customize the font of the tooltip text. The HighlightColor property is used to customize the point color while hovering for tooltip.

@{
    var border = new { color = "grey", width = 2 };
}
 <ejs-chart id="container" highlightColor="red">
        <e-chart-tooltipsettings enable="true" format="${series.name} ${point.x} : ${point.y}"
            fill="#7bb4eb" border="border">
        </e-chart-tooltipsettings>
        <e-chart-legendsettings visible="false"></e-chart-legendsettings>
        <e-chart-primaryxaxis valueType="Category"></e-chart-primaryxaxis>
        <e-series-collection>
            <e-series dataSource="ViewBag.dataSource" name="Germany" xName="x" width="2" opacity="1" yName="yValue" type="@Syncfusion.EJ2.Charts.ChartSeriesType.Column">
            </e-series>
        </e-series-collection>
</ejs-chart>
public IActionResult Index()
        {
            List<ColumnChartData> chartData = new List<ColumnChartData>
            {
                new ColumnChartData { x= "USA", yValue= 46 },
                new ColumnChartData { x= "GBR", yValue= 27 },
                new ColumnChartData { x= "CHN", yValue= 26 },
                new ColumnChartData { x= "UK", yValue= 26 },
                new ColumnChartData { x= "AUS", yValue= 26 },
                new ColumnChartData { x= "IND", yValue= 26 },
                new ColumnChartData { x= "DEN", yValue= 26 },
                new ColumnChartData { x= "MEX", yValue= 26 },
            };
            ViewBag.dataSource = chartData;
            return View();
        }
        public class ColumnChartData
        {
            public string x;
            public double yValue;
        }

Tooltip mapping name

By default, tooltip shows information of x and y value in points. You can show more information from data source in tooltip by using the TooltipMappingName property of the tooltip. You can use the ${point.tooltip} as place holders to display the specified tooltip content.

<ejs-chart id="container">
    <e-chart-tooltipsettings enable="true" format="${point.tooltip}">
    </e-chart-tooltipsettings>
    <e-chart-legendsettings visible="true"></e-chart-legendsettings>
    <e-chart-primaryxaxis valueType="Category"></e-chart-primaryxaxis>
    <e-series-collection>
        <e-series dataSource="ViewBag.dataSource" tooltipMappingName="text" name="Germany" xName="xValue" yName="yValue" type="@Syncfusion.EJ2.Charts.ChartSeriesType.Column">
        </e-series>
    </e-series-collection>
</ejs-chart>
public ActionResult Index()
        {
            List<GroupingChartData> chartData = new List<GroupingChartData>
            {

                new GroupingChartData { xValue = "China",         yValue = 26, text = "China: 26" },
                new GroupingChartData { xValue = "Russia",        yValue = 19, text = "Russia: 19" },
                new GroupingChartData { xValue = "Germany",       yValue = 17, text = "Germany: 17" },
                new GroupingChartData { xValue = "Japan",         yValue = 12, text = "Japan: 12" },
                new GroupingChartData { xValue = "France",        yValue = 10, text = "France: 10" },
                new GroupingChartData { xValue = "South Korea",   yValue = 9,  text = "South Korea: 9" },
                new GroupingChartData { xValue = "Great Britain", yValue = 27, text = "Great Britain: 27" },
                new GroupingChartData { xValue = "Italy",         yValue = 8,  text = "Italy: 8" },
                new GroupingChartData { xValue = "Australia",     yValue = 8,  text = "Australia: 8" },
                new GroupingChartData { xValue = "Netherlands",   yValue = 8,  text = "Netherlands: 8" },
                new GroupingChartData { xValue = "Hungary",       yValue = 8,  text = "Hungary: 8" },
                new GroupingChartData { xValue = "Brazil",        yValue = 7,  text = "Brazil: 7" },
                new GroupingChartData { xValue = "Spain",         yValue = 7,  text = "Spain: 7" },
                new GroupingChartData { xValue = "Kenya",         yValue = 6,  text = "Kenya: 6" }

            };
            ViewBag.dataSource = chartData;
            return View();
        }
        public class GroupingChartData
        {
            public string xValue;
            public double yValue;
            public string text;
        }

Enable highlight

By setting the EnableHighlight property to true, you can highlight all points in the hovered series while dimming points in other series, enhancing focus and clarity.

<ejs-chart id="container">
    <e-chart-tooltipsettings enable="true" format="${point.tooltip}" enableHighlight="true">
    </e-chart-tooltipsettings>
    <e-chart-legendsettings visible="true"></e-chart-legendsettings>
    <e-chart-primaryxaxis valueType="Category"></e-chart-primaryxaxis>
    <e-series-collection>
        <e-series dataSource="ViewBag.dataSource" tooltipMappingName="text" name="Germany" xName="xValue" yName="yValue" type="@Syncfusion.EJ2.Charts.ChartSeriesType.Column">
        </e-series>
    </e-series-collection>
</ejs-chart>
public ActionResult Index()
        {
            List<GroupingChartData> chartData = new List<GroupingChartData>
            {

                new GroupingChartData { xValue = "China",         yValue = 26, text = "China: 26" },
                new GroupingChartData { xValue = "Russia",        yValue = 19, text = "Russia: 19" },
                new GroupingChartData { xValue = "Germany",       yValue = 17, text = "Germany: 17" },
                new GroupingChartData { xValue = "Japan",         yValue = 12, text = "Japan: 12" },
                new GroupingChartData { xValue = "France",        yValue = 10, text = "France: 10" },
                new GroupingChartData { xValue = "South Korea",   yValue = 9,  text = "South Korea: 9" },
                new GroupingChartData { xValue = "Great Britain", yValue = 27, text = "Great Britain: 27" },
                new GroupingChartData { xValue = "Italy",         yValue = 8,  text = "Italy: 8" },
                new GroupingChartData { xValue = "Australia",     yValue = 8,  text = "Australia: 8" },
                new GroupingChartData { xValue = "Netherlands",   yValue = 8,  text = "Netherlands: 8" },
                new GroupingChartData { xValue = "Hungary",       yValue = 8,  text = "Hungary: 8" },
                new GroupingChartData { xValue = "Brazil",        yValue = 7,  text = "Brazil: 7" },
                new GroupingChartData { xValue = "Spain",         yValue = 7,  text = "Spain: 7" },
                new GroupingChartData { xValue = "Kenya",         yValue = 6,  text = "Kenya: 6" }

            };
            ViewBag.dataSource = chartData;
            return View();
        }
        public class GroupingChartData
        {
            public string xValue;
            public double yValue;
            public string text;
        }