Tooltip in ASP.NET MVC Accumulation chart component
18 Nov 201824 minutes to read
Tooltip for the accumulation chart can be enabled by using the Enable property.
@Html.EJS().AccumulationChart("container").Series(series =>
{
series.DataSource(ViewBag.dataSource)
.XName("xValue")
.YName("yValue")
.Name("Browser")
.Type(Syncfusion.EJ2.Charts.AccumulationType.Pie)
.ExplodeIndex(0).Add();
})
.EnableSmartLabels(true)
.Title("Mobile Browser Statistics")
.Tooltip(tp => tp.Enable(true))
.LegendSettings(ls => ls.Visible(false)).Render()public ActionResult Index()
{
List<PieChartData> chartData = new List<PieChartData>
{
new PieChartData { xValue = "Chrome", yValue = 37 },
new PieChartData { xValue = "UC Browser", yValue = 17 },
new PieChartData { xValue = "iPhone", yValue = 19 },
new PieChartData { xValue = "Others", yValue = 4 },
new PieChartData { xValue = "Opera", yValue = 11 },
new PieChartData { xValue = "Android", yValue = 12 },
};
ViewBag.dataSource = chartData;
return View();
}
public class PieChartData
{
public string xValue;
public double yValue;
}Header
We can specify header for the tooltip using Header property.
@Html.EJS().AccumulationChart("container").Series(series =>
{
series.DataSource(ViewBag.dataSource)
.XName("xValue")
.YName("yValue")
.Name("Browser")
.Type(Syncfusion.EJ2.Charts.AccumulationType.Pie)
.ExplodeIndex(0).Add();
})
.EnableSmartLabels(true)
.Title("Mobile Browser Statistics")
.Tooltip(tp => tp.Enable(true).Header("Pie Chart"))
.LegendSettings(ls => ls.Visible(false)).Render()public ActionResult Index()
{
List<PieChartData> chartData = new List<PieChartData>
{
new PieChartData { xValue = "Chrome", yValue = 37 },
new PieChartData { xValue = "UC Browser", yValue = 17 },
new PieChartData { xValue = "iPhone", yValue = 19 },
new PieChartData { xValue = "Others", yValue = 4 },
new PieChartData { xValue = "Opera", yValue = 11 },
new PieChartData { xValue = "Android", yValue = 12 },
};
ViewBag.dataSource = chartData;
return View();
}
public class PieChartData
{
public string xValue;
public double yValue;
}Format
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().AccumulationChart("container").Series(series =>
{
series.DataSource(ViewBag.dataSource)
.XName("xValue")
.YName("yValue")
.Name("Browser")
.Type(Syncfusion.EJ2.Charts.AccumulationType.Pie)
.ExplodeIndex(0).Add();
})
.EnableSmartLabels(true)
.Title("Mobile Browser Statistics")
.Tooltip(tp => tp.Enable(true).Format("format: '${point.x} : <b>${point.y}</b>'"))
.LegendSettings(ls => ls.Visible(false)).Render()public ActionResult Index()
{
List<PieChartData> chartData = new List<PieChartData>
{
new PieChartData { xValue = "Chrome", yValue = 37 },
new PieChartData { xValue = "UC Browser", yValue = 17 },
new PieChartData { xValue = "iPhone", yValue = 19 },
new PieChartData { xValue = "Others", yValue = 4 },
new PieChartData { xValue = "Opera", yValue = 11 },
new PieChartData { xValue = "Android", yValue = 12 },
};
ViewBag.dataSource = chartData;
return View();
}
public class PieChartData
{
public string xValue;
public double yValue;
}Inline tooltip formatting
The tooltip content can be formatted directly within the format property by adding DateTime or number format specifiers to supported tooltip tokens. This allows you to control how point and series values are displayed without using additional events.
A format specifier can be applied to a tooltip token by adding a colon (:) followed by the required format.
For example:
.Tooltip(tooltip => tooltip
.Enable(true)
.Format("${point.x:MMM yyyy} : <b>${point.y:n2}%</b>")
)In the above example, point.x is displayed in month-year format, and point.y is displayed with two decimal places.
Inline formatting can be applied to the following tooltip tokens:
-
point.x– Specifies the x-value or category value of the accumulation chart point. -
point.y– Specifies the numeric y-value of the accumulation chart point. -
point.percentage– Specifies the percentage contribution of the point value in the accumulation chart. -
point.text– Specifies the text value mapped to the point, when text mapping is configured. -
point.tooltip– Specifies the tooltip value mapped from the data source, when tooltip mapping is configured. -
point.index– Specifies the index position of the point in the accumulation chart. -
point.color– Specifies the fill color applied to the point. -
point.visible– Specifies the visibility state of the point. -
series.name– Specifies the name assigned to the accumulation chart series. -
series.type– Specifies the rendering type of the accumulation chart series, such asPie,Doughnut,Pyramid, orFunnel. -
series.opacity– Specifies the opacity value applied to the accumulation chart series. This value controls the visual transparency of the series and can be customized in the series configuration.
Important: The availability of point-specific tokens depends on the values configured in the data source and the accumulation chart series type. For example, point.percentage is useful for pie and doughnut charts, while point.text and point.tooltip depend on the corresponding field mappings. The series.name and series.type tokens return string values, so DateTime or number formatting is not applied to these tokens.
The following format types are supported:
- DateTime formats such as
MMM yyyy,MM:yy, anddd MMM - Number formats such as:
-
n2– number with two decimal places -
n0– number without decimals -
c2– currency format -
p1– percentage format -
e1– exponential notation
-
If the specified format does not match the resolved value type, the original value is displayed.
@using Syncfusion.EJ2.Charts
@(Html.EJS().AccumulationChart("container").Series(series =>
{
series.DataSource(ViewBag.dataSource)
.XName("x")
.YName("y")
.Type(Syncfusion.EJ2.Charts.AccumulationType.Pie)
.DataLabel(new AccumulationDataLabelSettings {
Visible = true,
Name = "text"
})
.Radius("70%")
.Add();
})
.Tooltip(tooltip => tooltip
.Enable(true)
.Format("${point.x:MMM yyyy} : <b>${point.y:n2}%</b>"
)
).LegendSettings(legend=>legend.Visible(false))
.Render())public ActionResult Index()
{
List<AccumulationChartData> chartData = new List<AccumulationChartData>
{
new AccumulationChartData { x = new DateTime(2024, 1, 1), y = 3 },
new AccumulationChartData { x = new DateTime(2024, 2, 1), y = 3.5 },
new AccumulationChartData { x = new DateTime(2024, 3, 1), y = 7 },
new AccumulationChartData { x = new DateTime(2024, 4, 1), y = 13.5 },
new AccumulationChartData { x = new DateTime(2024, 5, 1), y = 19 },
new AccumulationChartData { x = new DateTime(2024, 6, 1), y = 23.5 },
new AccumulationChartData { x = new DateTime(2024, 7, 1), y = 26 },
new AccumulationChartData { x = new DateTime(2024, 8, 1), y = 25 },
new AccumulationChartData { x = new DateTime(2024, 9, 1), y = 21 },
new AccumulationChartData { x = new DateTime(2024, 10, 1), y = 15 }
};
ViewBag.dataSource = chartData;
return View();
}
public class AccumulationChartData
{
public DateTime x;
public double y;
}Tooltip format
Any HTML element can be displayed in the tooltip by using the Template property.
@Html.EJS().AccumulationChart("container").Series(series =>
{
series.DataSource(ViewBag.dataSource)
.XName("xValue")
.YName("yValue")
.Name("Browser")
.Type(Syncfusion.EJ2.Charts.AccumulationType.Pie)
.ExplodeIndex(0).Add();
})
.EnableSmartLabels(true)
.Title("Mobile Browser Statistics")
.Tooltip(tp => tp.Enable(true).Template("<div id='templateWrap' style='background-color:#bd18f9;border-radius: 3px; float: right;padding: 2px;line-height: 20px;text-align: center;'>"+
"<img src='sun_annotation.png' />" +
"<div style='color:white; font-family:Roboto; font-style: medium; fontp-size:14px;float: right;padding: 2px;line-height: 20px;text-align: center;padding-right:6px'><span>${y}</span></div></div>" ))
.LegendSettings(ls => ls.Visible(false)).Render()public ActionResult Index()
{
List<PieChartData> chartData = new List<PieChartData>
{
new PieChartData { xValue = "Chrome", yValue = 37 },
new PieChartData { xValue = "UC Browser", yValue = 17 },
new PieChartData { xValue = "iPhone", yValue = 19 },
new PieChartData { xValue = "Others", yValue = 4 },
new PieChartData { xValue = "Opera", yValue = 11 },
new PieChartData { xValue = "Android", yValue = 12 },
};
ViewBag.dataSource = chartData;
return View();
}
public class PieChartData
{
public string xValue;
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().AccumulationChart("container").Series(series =>
{
series.DataSource(ViewBag.dataSource)
.XName("xValue")
.YName("yValue")
.Name("Browser")
.Type(Syncfusion.EJ2.Charts.AccumulationType.Pie)
.Add();
})
.Title("Mobile Browser Statistics")
.Tooltip(tp => tp.Enable(true).Location(lc => lc.X(200).Y(20)))
.LegendSettings(ls => ls.Visible(false)).Render())public ActionResult Index()
{
List<PieChartData> chartData = new List<PieChartData>
{
new PieChartData { xValue = "Chrome", yValue = 37 },
new PieChartData { xValue = "UC Browser", yValue = 17 },
new PieChartData { xValue = "iPhone", yValue = 19 },
new PieChartData { xValue = "Others", yValue = 4 },
new PieChartData { xValue = "Opera", yValue = 11 },
new PieChartData { xValue = "Android", yValue = 12 }
};
ViewBag.dataSource = chartData;
return View();
}
public class PieChartData
{
public string xValue;
public double yValue;
}Customization
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 can be used to change the color of the data point when hovering.
@Html.EJS().AccumulationChart("container").Series(series =>
{
series.DataSource(ViewBag.dataSource)
.XName("xValue")
.YName("yValue")
.Name("Browser")
.Type(Syncfusion.EJ2.Charts.AccumulationType.Pie)
.ExplodeIndex(0).Add();
})
.EnableSmartLabels(true)
.Title("Mobile Browser Statistics")
.Tooltip(tp => tp.Enable(true).Format(format: "${series.name} ${point.x} : ${point.y}")
.Fill('#7bb4eb')
})
.LegendSettings(ls => ls.Visible(false)).Render()public ActionResult Index()
{
List<PieChartData> chartData = new List<PieChartData>
{
new PieChartData { xValue = "Chrome", yValue = 37 },
new PieChartData { xValue = "UC Browser", yValue = 17 },
new PieChartData { xValue = "iPhone", yValue = 19 },
new PieChartData { xValue = "Others", yValue = 4 },
new PieChartData { xValue = "Opera", yValue = 11 },
new PieChartData { xValue = "Android", yValue = 12 },
};
ViewBag.dataSource = chartData;
return View();
}
public class PieChartData
{
public string xValue;
public double yValue;
}To customize individual tooltip
Using TooltipRender event, you can customize a tooltip for particular point. event, you can customize a tooltip for particular point.
@Html.EJS().AccumulationChart("container").Series(series =>
{
series.DataSource(ViewBag.dataSource)
.XName("xValue")
.YName("yValue")
.Name("Browser")
.Type(Syncfusion.EJ2.Charts.AccumulationType.Pie)
.ExplodeIndex(0).Add();
})
.EnableSmartLabels(true)
.Title("Mobile Browser Statistics")
.Tooltip(tp => tp.Enable(true))
.PointRender("pointRender")
.LegendSettings(ls => ls.Visible(false)).Render()
<script>
var pointRender = function (args) {
if (args.point.index === 3) {
args.text = args.point.xValue + '' + ':' + args.point.yValue + '' + ' ' +'customtext';
args.textStyle.color = '#f48042';
}
};
</script>public ActionResult Index()
{
List<PieChartData> chartData = new List<PieChartData>
{
new PieChartData { xValue = "Chrome", yValue = 37 },
new PieChartData { xValue = "UC Browser", yValue = 17 },
new PieChartData { xValue = "iPhone", yValue = 19 },
new PieChartData { xValue = "Others", yValue = 4 },
new PieChartData { xValue = "Opera", yValue = 11 },
new PieChartData { xValue = "Android", yValue = 12 },
};
ViewBag.dataSource = chartData;
return View();
}
public class PieChartData
{
public string xValue;
public double yValue;
}Tooltip mapping name
By default, tooltip shows information of x and y value in points. You can show more information from datasource 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().AccumulationChart("container")
.Series(sr =>
{
sr.Type(Syncfusion.EJ2.Charts.AccumulationType.Pie)
.XName("xValue")
.YName("yValue")
.TooltipMappingName("text")
.Name("RIO")
.Radius("70%")
.StartAngle(0)
.EndAngle(360)
.InnerRadius("0%")
.DataSource(ViewBag.dataSource).Add();
})
.Tooltip(tp => tp.Enable(true).Format("${point.tooltip}"))
.LegendSettings(leg => leg.Visible(true))
.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;
}Enable highlight
By setting the EnableHighlight property to true, the hovered pie slice is highlighted, while the remaining slices are dimmed, enhancing focus and clarity.
@{
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" }
};
}
<ejs-accumulationchart id="container">
<e-accumulationchart-tooltipsettings enable="true" enableHighlight="true"></e-accumulationchart-tooltipsettings>
<e-accumulationchart-legendsettings visible="true">
</e-accumulationchart-legendsettings>
<e-accumulation-series-collection>
<e-accumulation-series tooltipMappingName="text" dataSource="chartData" xName="xValue" yName="yValue" name="Browser">
</e-accumulation-series>
</e-accumulation-series-collection>
</ejs-accumulationchart>...
public class GroupingChartData
{
public string xValue;
public double yValue;
public string text;
}Follow pointer
The follow pointer feature enables the tooltip to follow the mouse cursor or touch pointer as users interact with the accumulation chart. This provides a more dynamic experience by keeping the tooltip close to the user’s interaction point.
Enable this feature by setting the FollowPointer property to true in the tooltip.
@Html.EJS().AccumulationChart("container")
.EnableAnimation(true)
.Series(series =>
{
series.XName("x")
.YName("y")
.Name("Browser")
.BorderRadius(3)
.DataSource(ViewBag.dataSource)
.Add();
})
.Tooltip(tt => tt
.Enable(true)
.FollowPointer(true)
.Format("<b>${point.x}</b><br>Percentage: <b>${point.y}%</b>")
)
.Render()using Microsoft.AspNetCore.Mvc;
using System.Collections.Generic;
namespace EJ2CoreSampleBrowser.Controllers.Chart
{
public partial class ChartController : Controller
{
public IActionResult FollowPointer()
{
List<ChartData> chartData = new List<ChartData>
{
new ChartData { x = "Coal", y = 34.4, text = "Coal: 34.4%" },
new ChartData { x = "Natural Gas", y = 22.1, text = "Natural Gas: 22.1%" },
new ChartData { x = "Hydro", y = 14.4, text = "Hydro: 14.4%" },
new ChartData { x = "Nuclear", y = 9.0, text = "Nuclear: 9.0%" },
new ChartData { x = "Wind", y = 8.1, text = "Wind: 8.1%" },
new ChartData { x = "Others", y = 12.0, text = "Others: 12.0%" }
};
ViewBag.dataSource = chartData;
return View();
}
public class ChartData
{
public string x;
public double y;
public string text;
}
}
}