How can I help you?
Tooltip in ASP.NET MVC Chart Component
23 Mar 202624 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.
@Html.EJS().Chart("container").Series(series =>
{
series.Type(Syncfusion.EJ2.Charts.ChartSeriesType.Column).
Marker(ViewBag.Marker).
XName("x").
YName("yValue").
DataSource(ViewBag.dataSource).
Name("Gold").
Width(2).Add();
}).
PrimaryXAxis(px => px.Interval(1).ValueType(Syncfusion.EJ2.Charts.ValueType.Category)).
Title("Olympic Medal Counts - RIO").Tooltip(tt => tt.Enable(true)).Render()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.
@(Html.EJS().Chart("container").Series(series =>
{
series.Type(Syncfusion.EJ2.Charts.ChartSeriesType.Column).
XName("xValue").
YName("yValue").
DataSource(ViewBag.dataSource).
Name("Gold").
Width(2).Add();
}).
PrimaryXAxis(px => px.Interval(1).ValueType(Syncfusion.EJ2.Charts.ValueType.Category)).LegendSettings(ls => ls.Visible(false))
.Title("Olympic Medal Counts - RIO").Tooltip(tt => tt.Enable(true).Location(lc => lc.X(120).Y(20))).Render())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.
@Html.EJS().Chart("container").Series(series =>
{
series.Type(Syncfusion.EJ2.Charts.ChartSeriesType.Column).
Marker(ViewBag.Marker).
XName("x").
YName("yValue").
DataSource(ViewBag.dataSource).
Name("Gold").
Width(2).Add();
}).
PrimaryXAxis(px => px.Interval(1).ValueType(Syncfusion.EJ2.Charts.ValueType.Category)).
Title("Olympic Medal Counts - RIO").
Tooltip(tt => tt.Enable(true).
Header("medal count").
Format("${series.name} ${point.x} : ${point.y}")).Render()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.
@Html.EJS().Chart("container").Series(series =>
{
series.Type(Syncfusion.EJ2.Charts.ChartSeriesType.Column).
Marker(ViewBag.Marker).
XName("x").
YName("yValue").
DataSource(ViewBag.dataSource).
Name("Gold").
Width(2).Add();
}).
PrimaryXAxis(px => px.Interval(1).ValueType(Syncfusion.EJ2.Charts.ValueType.Category)).
Title("Olympic Medal Counts - RIO").
Tooltip(tt => tt.Enable(true).
header("medal count").
template=("#Medal")).Render()
<script id="Medal" type="text/x-template">
<div id='templateWrap'>
<table style="width:100%; border: 1px solid black;">
<tr><th colspan="2" bgcolor="#00FFFF">Medal</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.
@Html.EJS().Chart("container").Series(series =>
{
series.Type(Syncfusion.EJ2.Charts.ChartSeriesType.Column).
Marker(ViewBag.Marker).
XName("x").
YName("yValue").
DataSource(ViewBag.dataSource).
Name("Gold").
Width(2).Add();
}).
HighlightColor("red").
PrimaryXAxis(px => px.Interval(1).ValueType(Syncfusion.EJ2.Charts.ValueType.Category)).
Title("Olympic Medal Counts - RIO").Tooltip(tt => tt.Enable(true).
Format("<b>${point.x} : ${point.y}</b>").
Fill('#7bb4eb')).Render()
}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.
@(Html.EJS().Chart("container").Series(series =>
{
series.Type(Syncfusion.EJ2.Charts.ChartSeriesType.Column).
XName("xValue").
YName("yValue").
TooltipMappingName("text").
DataSource(ViewBag.dataSource).
Name("Gold").
Width(2).Add();
}).
PrimaryXAxis(px => px.ValueType(Syncfusion.EJ2.Charts.ValueType.Category).Interval(1))
.Tooltip(tp => tp.Enable(true).Format("${point.tooltip}"))
.Render()
)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;
}Split tooltip
The split tooltip displays a separate tooltip for each series at the same data point, making it easier to compare values across multiple series.
Enable this feature by setting the split property to true:
@Html.EJS().Chart("container")
.PrimaryXAxis(px => px.ValueType(Syncfusion.EJ2.Charts.ValueType.Category))
.PrimaryYAxis(py => py.Title("Value"))
.LegendSettings(l => l.Visible(true))
.Tooltip(tt => tt.Enable(true).Split(true))
.Series(series =>
{
series.Type(Syncfusion.EJ2.Charts.ChartSeriesType.Line)
.XName("x")
.YName("y")
.Name("Vietnam")
.Marker(m => m.Visible(true))
.DataSource(ViewBag.vietnamData)
.Add();
series.Type(Syncfusion.EJ2.Charts.ChartSeriesType.Line)
.XName("x")
.YName("y")
.Name("Indonesia")
.Marker(m => m.Visible(true))
.DataSource(ViewBag.indonesiaData)
.Add();
series.Type(Syncfusion.EJ2.Charts.ChartSeriesType.Line)
.XName("x")
.YName("y")
.Name("France")
.Marker(m => m.Visible(true))
.DataSource(ViewBag.franceData)
.Add();
series.Type(Syncfusion.EJ2.Charts.ChartSeriesType.Line)
.XName("x")
.YName("y")
.Name("Poland")
.Marker(m => m.Visible(true))
.DataSource(ViewBag.polandData)
.Add();
series.Type(Syncfusion.EJ2.Charts.ChartSeriesType.Line)
.XName("x")
.YName("y")
.Name("Mexico")
.Marker(m => m.Visible(true))
.DataSource(ViewBag.mexicoData)
.Add();
})
.Render()using Microsoft.AspNetCore.Mvc;
using System.Collections.Generic;
namespace EJ2CoreSampleBrowser.Controllers.Chart
{
public partial class ChartController : Controller
{
public IActionResult SplitTooltip()
{
List<ChartData> vietnamData = new List<ChartData>
{
new ChartData { x = 2016, y = 7.8 },
new ChartData { x = 2017, y = 10.3 },
new ChartData { x = 2018, y = 15.5 },
new ChartData { x = 2019, y = 17.5 },
new ChartData { x = 2020, y = 19.5 },
new ChartData { x = 2021, y = 23.0 },
new ChartData { x = 2022, y = 20.0 },
new ChartData { x = 2023, y = 19.0 },
new ChartData { x = 2024, y = 22.1 }
};
List<ChartData> indonesiaData = new List<ChartData>
{
new ChartData { x = 2016, y = 4.8 },
new ChartData { x = 2017, y = 5.2 },
new ChartData { x = 2018, y = 6.2 },
new ChartData { x = 2019, y = 7.8 },
new ChartData { x = 2020, y = 9.3 },
new ChartData { x = 2021, y = 14.3 },
new ChartData { x = 2022, y = 15.6 },
new ChartData { x = 2023, y = 16.0 },
new ChartData { x = 2024, y = 17.0 }
};
List<ChartData> franceData = new List<ChartData>
{
new ChartData { x = 2016, y = 14.6 },
new ChartData { x = 2017, y = 15.5 },
new ChartData { x = 2018, y = 15.4 },
new ChartData { x = 2019, y = 14.4 },
new ChartData { x = 2020, y = 11.6 },
new ChartData { x = 2021, y = 13.9 },
new ChartData { x = 2022, y = 12.1 },
new ChartData { x = 2023, y = 10.0 },
new ChartData { x = 2024, y = 10.8 }
};
List<ChartData> polandData = new List<ChartData>
{
new ChartData { x = 2016, y = 8.9 },
new ChartData { x = 2017, y = 10.3 },
new ChartData { x = 2018, y = 10.8 },
new ChartData { x = 2019, y = 9.0 },
new ChartData { x = 2020, y = 7.9 },
new ChartData { x = 2021, y = 8.5 },
new ChartData { x = 2022, y = 7.4 },
new ChartData { x = 2023, y = 6.4 },
new ChartData { x = 2024, y = 7.1 }
};
List<ChartData> mexicoData = new List<ChartData>
{
new ChartData { x = 2016, y = 19.0 },
new ChartData { x = 2017, y = 20.0 },
new ChartData { x = 2018, y = 20.2 },
new ChartData { x = 2019, y = 18.4 },
new ChartData { x = 2020, y = 16.8 },
new ChartData { x = 2021, y = 18.5 },
new ChartData { x = 2022, y = 18.4 },
new ChartData { x = 2023, y = 16.3 },
new ChartData { x = 2024, y = 13.7 }
};
ViewBag.vietnamData = vietnamData;
ViewBag.indonesiaData = indonesiaData;
ViewBag.franceData = franceData;
ViewBag.polandData = polandData;
ViewBag.mexicoData = mexicoData;
return View();
}
public class ChartData
{
public double x;
public double y;
}
}
}Follow pointer
The follow pointer feature enables the tooltip to follow the mouse cursor or touch pointer as users interact with the chart. This provides a more dynamic and intuitive experience by keeping the tooltip close to the user’s point of interaction.
Enable this feature by setting the followPointer property to true:
@Html.EJS().Chart("container")
.PrimaryXAxis(px => px.ValueType(Syncfusion.EJ2.Charts.ValueType.Category))
.PrimaryYAxis(py => py.Title("Value"))
.LegendSettings(l => l.Visible(true))
.Tooltip(tt => tt.Enable(true).FollowPointer(true))
.Series(series =>
{
series.Type(Syncfusion.EJ2.Charts.ChartSeriesType.Column)
.XName("x")
.YName("y")
.Name("Vietnam")
.Marker(m => m.Visible(true))
.DataSource(ViewBag.vietnamData)
.Add();
series.Type(Syncfusion.EJ2.Charts.ChartSeriesType.Column)
.XName("x")
.YName("y")
.Name("France")
.Marker(m => m.Visible(true))
.DataSource(ViewBag.franceData)
.Add();
series.Type(Syncfusion.EJ2.Charts.ChartSeriesType.Column)
.XName("x")
.YName("y")
.Name("Mexico")
.Marker(m => m.Visible(true))
.DataSource(ViewBag.mexicoData)
.Add();
})
.Render()public IActionResult FollowPointer()
{
List<ChartData> vietnamData = new List<ChartData>
{
new ChartData { x = 2016, y = 7.8 },
new ChartData { x = 2017, y = 10.3 },
new ChartData { x = 2018, y = 15.5 },
new ChartData { x = 2019, y = 17.5 },
new ChartData { x = 2020, y = 19.5 },
new ChartData { x = 2021, y = 23.0 },
new ChartData { x = 2022, y = 20.0 },
new ChartData { x = 2023, y = 19.0 },
new ChartData { x = 2024, y = 22.1 }
};
List<ChartData> franceData = new List<ChartData>
{
new ChartData { x = 2016, y = 14.6 },
new ChartData { x = 2017, y = 15.5 },
new ChartData { x = 2018, y = 15.4 },
new ChartData { x = 2019, y = 14.4 },
new ChartData { x = 2020, y = 11.6 },
new ChartData { x = 2021, y = 13.9 },
new ChartData { x = 2022, y = 12.1 },
new ChartData { x = 2023, y = 10.0 },
new ChartData { x = 2024, y = 10.8 }
};
List<ChartData> mexicoData = new List<ChartData>
{
new ChartData { x = 2016, y = 19.0 },
new ChartData { x = 2017, y = 20.0 },
new ChartData { x = 2018, y = 20.2 },
new ChartData { x = 2019, y = 18.4 },
new ChartData { x = 2020, y = 16.8 },
new ChartData { x = 2021, y = 18.5 },
new ChartData { x = 2022, y = 18.4 },
new ChartData { x = 2023, y = 16.3 },
new ChartData { x = 2024, y = 13.7 }
};
ViewBag.vietnamData = vietnamData;
ViewBag.franceData = franceData;
ViewBag.mexicoData = mexicoData;
return View();
}
public class ChartData
{
public double x;
public double y;
}Tooltip distance
The tooltip distance property controls the spacing between the tooltip and the mouse pointer or target data point. This prevents the tooltip from overlapping with the cursor or nearby chart elements, improving readability.
Set the distance property to specify the gap in pixels:
@Html.EJS().Chart("container")
.PrimaryXAxis(px => px.ValueType(Syncfusion.EJ2.Charts.ValueType.Category))
.PrimaryYAxis(py => py.Title("Value"))
.LegendSettings(l => l.Visible(true))
.Tooltip(tt => tt.Enable(true).Distance(20))
.Series(series =>
{
series.Type(Syncfusion.EJ2.Charts.ChartSeriesType.Column)
.XName("x")
.YName("y")
.Name("Vietnam")
.Marker(m => m.Visible(true))
.DataSource(ViewBag.vietnamData)
.Add();
series.Type(Syncfusion.EJ2.Charts.ChartSeriesType.Column)
.XName("x")
.YName("y")
.Name("Poland")
.Marker(m => m.Visible(true))
.DataSource(ViewBag.polandData)
.Add();
})
.Render()using Microsoft.AspNetCore.Mvc;
using System.Collections.Generic;
namespace EJ2CoreSampleBrowser.Controllers.Chart
{
public partial class ChartController : Controller
{
public IActionResult TooltipDistance()
{
List<ChartData> vietnamData = new List<ChartData>
{
new ChartData { x = 2016, y = 7.8 },
new ChartData { x = 2017, y = 10.3 },
new ChartData { x = 2018, y = 15.5 },
new ChartData { x = 2019, y = 17.5 },
new ChartData { x = 2020, y = 19.5 },
new ChartData { x = 2021, y = 23.0 },
new ChartData { x = 2022, y = 20.0 },
new ChartData { x = 2023, y = 19.0 },
new ChartData { x = 2024, y = 22.1 }
};
List<ChartData> polandData = new List<ChartData>
{
new ChartData { x = 2016, y = 8.9 },
new ChartData { x = 2017, y = 10.3 },
new ChartData { x = 2018, y = 10.8 },
new ChartData { x = 2019, y = 9.0 },
new ChartData { x = 2020, y = 7.9 },
new ChartData { x = 2021, y = 8.5 },
new ChartData { x = 2022, y = 7.4 },
new ChartData { x = 2023, y = 6.4 },
new ChartData { x = 2024, y = 7.1 }
};
ViewBag.vietnamData = vietnamData;
ViewBag.polandData = polandData;
return View();
}
public class ChartData
{
public double x;
public double y;
}
}
}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 class GroupingChartData
{
public string xValue;
public double yValue;
public string text;
}Closest tooltip
The ShowNearestTooltip property in the chart tooltip displays tooltips based on the data points closest to the cursor.
@Html.EJS().Chart("container").Series(series =>
{
series.Type(Syncfusion.EJ2.Charts.ChartSeriesType.StepLine)
.XName("X")
.YName("Y")
.Marker(mr => mr.Visible(true).Width(10).Height(10))
.Name("China")
.Width(2)
.DataSource(ViewBag.dataSource)
.Add();
series.Type(Syncfusion.EJ2.Charts.ChartSeriesType.StepLine)
.XName("X")
.YName("Y1")
.Marker(mr => mr.Visible(true).Width(10).Height(10))
.Name("Australia")
.Width(2)
.DataSource(ViewBag.dataSource)
.Add();
series.Type(Syncfusion.EJ2.Charts.ChartSeriesType.StepLine)
.XName("X")
.YName("Y2")
.Marker(mr => mr.Visible(true).Width(10).Height(10))
.Name("Japan")
.Width(2)
.DataSource(ViewBag.dataSource)
.Add();
}
).PrimaryXAxis(px => px.ValueType(Syncfusion.EJ2.Charts.ValueType.DateTime).EdgeLabelPlacement(Syncfusion.EJ2.Charts.EdgeLabelPlacement.Shift).Title("Years").LabelFormat("y").IntervalType(Syncfusion.EJ2.Charts.IntervalType.Years).LineStyle(ls=>ls.Width(0))
).PrimaryYAxis(py => py.Title("Percentage (%)").LabelFormat("{value}%").Minimum(0).Maximum(20).Interval(4)
).LegendSettings(leg => leg.Visible(true)).Title("Unemployment Rates 1975-2010").Tooltip(tt => tt.Enable(true).EnableHighlight(true).ShowNearestTooltip(true)).Render()public IActionResult Index()
{
List<ColumnChartData> chartData = new List<ColumnChartData>
{
new ColumnChartData { X = new DateTime(1975, 01, 01), Y = 16, Y1 = 10, Y2 = 4.5 },
new ColumnChartData { X = new DateTime(1980, 01, 01), Y = 12.5, Y1 = 7.5, Y2 = 5 },
new ColumnChartData { X = new DateTime(1985, 01, 01), Y = 19, Y1 = 11, Y2 = 6.5 },
new ColumnChartData { X = new DateTime(1990, 01, 01), Y = 14.4, Y1 = 7, Y2 = 4.4 },
new ColumnChartData { X = new DateTime(1995, 01, 01), Y = 11.5, Y1 = 8, Y2 = 5 },
new ColumnChartData { X = new DateTime(2000, 01, 01), Y = 14, Y1 = 6, Y2 = 1.5 },
new ColumnChartData { X = new DateTime(2005, 01, 01), Y = 10, Y1 = 3.5, Y2 = 2.5 },
new ColumnChartData { X = new DateTime(2010, 01, 01), Y = 16, Y1 = 7, Y2 = 3.7 }
};
ViewBag.dataSource = chartData;
return View();
}
public class ColumnChartData
{
public DateTime X;
public double Y;
public double Y1;
public double Y2;
}