Group Smaller Slices in Pie Charts to Improve Readability

梦想与她 提交于 2019-12-24 00:52:29

问题


I want to group data thar have under 10% percentage to be grouped to slice of pie named others. Is it possible? Pie-chart

        series: [{
            type: 'pie',
            name: 'Browser share',
            data: [
                ['Firefox',   45.0],
                ['IE',       26.8],
                {
                    name: 'Chrome',
                    y: 12.8,
                    sliced: true,
                    selected: true
                },
                ['Safari',    8.5],
                ['Opera',     6.2]
            ]
        }]

回答1:


You just need to calculate slightly different data. Iterate over the entries looking for items with < 10%. Add these to an 'other' category.

Something like this:

 var data = [
            ['Firefox',   45.0],
            ['IE',       26.8],
            {
                name: 'Chrome',
                y: 12.8,
                sliced: true,
                selected: true
            },
            ['Safari',    8.5],
            ['Opera',     6.2]
        ];
var newData=[];
var other=0.0;
for (var slice in data) {

    if (data[slice][1] < 10) {
        other += data[slice][1];
    } else {
        newData.push(data[slice]);
    }
}
newData.push(['other',other]);

http://jsfiddle.net/q25u2hyr/



来源:https://stackoverflow.com/questions/28883606/group-smaller-slices-in-pie-charts-to-improve-readability

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!