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. (Last updated on: November 16, 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Doughnut Chart - Recalculating visible series percetanges

Thread ID:

Created:

Updated:

Platform:

Replies:

127574 Nov 24,2016 01:02 PM UTC Nov 28,2016 10:10 AM UTC ASP.NET MVC 3
loading
Tags: Chart
Matthew Holdsworth
Asked On November 24, 2016 01:02 PM UTC

I am using the ToggleSeriesVisibility option for a Doughnut chart.  I want to recalculate the percentage labels for each remaining visible series point.  

However when i loop each series points its always returning true for its visible state (see yellow highlighted code).  Am I using the wrong property?

function pieChartSeriesChange(args) {
  
    var series = args.model.series;
  
    for (var i = 0; i < series.length; i++) {
        var total = 0;

        //Calculate total value 
        for (var j = 0; j < series[i].points.length; j++) 
       {
             if (series[i].points[j].visible ) { total += series[i].points[j].y; }
       }
 
 
        for (j = 0; j < series[i].points.length; j++)
            series[i].points[j].text = series[i].points[j].x + ':- ' + (series[i].points[j].y / total * 100).toFixed(2) + '%';
    }
}

Dharanidharan Dharmasivam [Syncfusion]
Replied On November 25, 2016 01:36 PM UTC

Hi Matthew, 

Thanks for using Syncfusion product. 

We have analyzed your query. Since the visible property in points is a public API, we can’t override its value in source while toggle the visibility by clicking legend. But you can get this in _visibility in the point as an work around. And also you can reject the hidden point of a series to find the total using the below code snippet, since the hidden point will not be taken in account for finding overall percentage. 

ASP.NET MVC: 
@(Html.EJ().Chart("container") 
    //... 
    .LegendItemClick("pieChartSeriesChange") 
) 

function pieChartSeriesChange(args) { 
        var series = args.model.series; 
        for (var i = 0; i < series.length; i++) { 
            var total = 0; 
            //Calculate total value 
            for (var j = 0; j < series[i].points.length; j++) { 
                if (series[i].points[j]._visibility == "visible" && args.data.legendItem.LegendItem.PointIndex != j)  
                    total += series[i].points[j].y; 
            } 
            for (j = 0; j < series[i].points.length; j++) 
                series[i].points[j].text = series[i].points[j].x + ':- ' + (series[i].points[j].y / total * 100).toFixed(2) + '%'; 
        } 
    } 

Screenshot: 
 
For your reference, we have attached the sample. Kindly find the sample from below location, 
  
Thanks, 
Dharani. 


Matthew Holdsworth
Replied On November 25, 2016 02:14 PM UTC

Thanks for the info,

I changed the process I changed the process slightly by using the event Series Rendering and removing the additional check you add rgs.data.legendItem.LegendItem.PointIndex != j



Dharanidharan Dharmasivam [Syncfusion]
Replied On November 28, 2016 10:10 AM UTC

Hi Matthew, 
 
Thanks for your update.  
 
Kindly revert us, if you need further assistance on this.  

Thanks, 
Dharani. 


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

;