Tooltip in ASP.NET CORE Accumulation chart component

20 Dec 202324 minutes to read

Tooltip for the accumulation chart can be enabled by using the Enable property.

<ejs-accumulationchart id="container" title="Mobile Browser Statistics">
         <e-accumulationchart-tooltipsettings enable="true"></e-accumulationchart-tooltipsettings>
            <e-accumulationchart-legendsettings visible="false">
            </e-accumulationchart-legendsettings>
            <e-accumulation-series-collection>
                <e-accumulation-series dataSource="ViewBag.dataSource" xName="xValue" yName="yValue" name="Browser">
                </e-accumulation-series>
            </e-accumulation-series-collection>
        </ejs-accumulationchart>
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;
        }

We can specify header for the tooltip using Header property.

<ejs-accumulationchart id="container" title="Mobile Browser Statistics">
         <e-accumulationchart-tooltipsettings enable="true" header="Pie chart"></e-accumulationchart-tooltipsettings>
            <e-accumulationchart-legendsettings visible="false">
            </e-accumulationchart-legendsettings>
            <e-accumulation-series-collection>
                <e-accumulation-series dataSource="ViewBag.dataSource" xName="xValue" yName="yValue" name="Browser">
                </e-accumulation-series>
            </e-accumulation-series-collection>
        </ejs-accumulationchart>
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.

<ejs-accumulationchart id="container" title="Mobile Browser Statistics">
         <e-accumulationchart-tooltipsettings enable="true" Format="format: '${point.x} : <b>${point.y}</b>'"></e-accumulationchart-tooltipsettings>
            <e-accumulationchart-legendsettings visible="false">
            </e-accumulationchart-legendsettings>
            <e-accumulation-series-collection>
                <e-accumulation-series dataSource="ViewBag.dataSource" xName="xValue" yName="yValue" name="Browser">
                </e-accumulation-series>
            </e-accumulation-series-collection>
        </ejs-accumulationchart>
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 format

Any HTML element can be displayed in the tooltip by using the Template property.

<ejs-accumulationchart id="container" title="Mobile Browser Statistics">
         <e-accumulationchart-tooltipsettings 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>" ))
                 ></e-accumulationchart-tooltipsettings>
            <e-accumulationchart-legendsettings visible="false">
            </e-accumulationchart-legendsettings>
            <e-accumulation-series-collection>
                <e-accumulation-series dataSource="ViewBag.dataSource" xName="xValue" yName="yValue" name="Browser">
                </e-accumulation-series>
            </e-accumulation-series-collection>
        </ejs-accumulationchart>
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.

<ejs-accumulationchart id="container" title="Mobile Browser Statistics">
    <e-accumulationchart-tooltipsettings enable="true">
        <e-tooltipsettings-location x="200" y="20"></e-tooltipsettings-location>
    </e-accumulationchart-tooltipsettings>
    <e-accumulationchart-legendsettings visible="false">
    </e-accumulationchart-legendsettings>
    <e-accumulation-series-collection>
        <e-accumulation-series dataSource="ViewBag.dataSource" xName="xValue" yName="yValue" name="Browser">
        </e-accumulation-series>
    </e-accumulation-series-collection>
</ejs-accumulationchart>
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.

<ejs-accumulationchart id="container" title="Mobile Browser Statistics">
         <e-accumulationchart-tooltipsettings enable="true" format="${series.name} ${point.x} : ${point.y}"
            fill="#7bb4eb"></e-accumulationchart-tooltipsettings>
            <e-accumulationchart-legendsettings visible="false">
            </e-accumulationchart-legendsettings>
            <e-accumulation-series-collection>
                <e-accumulation-series dataSource="ViewBag.dataSource" xName="xValue" yName="yValue" name="Browser">
                </e-accumulation-series>
            </e-accumulation-series-collection>
        </ejs-accumulationchart>
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.

<ejs-accumulationchart id="container" title="Mobile Browser Statistics" tooltipRender="tooltipRender">
                    <e-accumulationchart-tooltipsettings enable="true"></e-accumulationchart-tooltipsettings>
                    <e-accumulationchart-legendsettings visible="false">
                    </e-accumulationchart-legendsettings>
                    <e-accumulation-series-collection>
                        <e-accumulation-series dataSource="ViewBag.dataSource" xName="xValue" yName="yValue" name="Browser">
                        </e-accumulation-series>
                    </e-accumulation-series-collection>
                </ejs-accumulationchart>

        <script>
            var tooltipRender = function (args) {
                if (args.point.index === 3) {
                    args.text = args.point.x + '' + ':' + args.point.y + '' + ' ' + 'customtext';
                    args.fill = 'red';
                }
            };
        </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.

<ejs-accumulationchart id="container">
    <e-accumulationchart-tooltipsettings enable="true" format="${point.tooltip}"></e-accumulationchart-tooltipsettings>
    <e-accumulationchart-legendsettings visible="true">
    </e-accumulationchart-legendsettings>
    <e-accumulation-series-collection>
        <e-accumulation-series tooltipMappingName="text" dataSource="ViewBag.dataSource" xName="xValue" yName="yValue" name="Browser">
        </e-accumulation-series>
    </e-accumulation-series-collection>
</ejs-accumulationchart>
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;
        }