We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Display percentage in tooltip

Hello

Is there a way to display the value as a percentage of the total in a tooltip hoover. Do I have to calculate in my datasource and use the TooltipMappingName or is there an out of the box method?

Thanks


3 Replies

DG Durga Gopalakrishnan Syncfusion Team February 3, 2023 02:10 PM UTC

Hi Ditchford,


Greetings from Syncfusion.


We suggest you to sepcify tooltip format as ${point.percentage} to display percentage value for accumulation chart and TooltipRender event to customize the chart series tooltip text. We have prepared sample based on your requirement. Please check with below snippet and sample.


<SfChart>

    <ChartEvents TooltipRender="OnTooltipRender"></ChartEvents>

    <ChartTooltipSettings Enable=true></ChartTooltipSettings>

</SfChart>

 

<SfAccumulationChart>

   <AccumulationChartTooltipSettings Format="${point.percentage}%"> </AccumulationChartTooltipSettings>

</SfAccumulationChart>

@code {

   public double totalSum = 0;

   protected override void OnInitialized()

    {

        for (int i = 0; i < MedalDetails.Count; i++)

        {

            totalSum = totalSum + Convert.ToInt16(MedalDetails[i].YValue);

        }

    }

    public void OnTooltipRender(TooltipRenderEventArgs args)

    {

        var percentage = (Convert.ToDouble(args.Data.PointY) / totalSum) * 100;

        args.Text = Math.Round(percentage, 2) + "%";

    }}




Sample : https://www.syncfusion.com/downloads/support/directtrac/general/ze/TooltipPerc-83147131.zip


Kindly revert us if you have any concerns.


Regards,

Durga Gopalakrishnan.



DI Ditchford replied to Durga Gopalakrishnan February 6, 2023 06:05 AM UTC

Hey


Great. Thank you.





DG Durga Gopalakrishnan Syncfusion Team February 7, 2023 07:10 AM UTC

Ditchford,


Most welcome. Please get back to us if you need any further assistance. We are always happy in assisting you.


Loader.
Up arrow icon