2017-03-09 27 views
0

我有一个饼图系列的数据,从最高值到最低值排序。我想让饼图分出第一个(最大)值。我尝试了一些没有成功的组合。我的饼图代码如下。Highcharts Pie,系列片第一项

如何通过初始化饼图来做到这一点?

 $(divID).highcharts({ 
      credits: false, 
      chart: { 
       plotBackgroundColor: null, 
       plotBorderWidth: null, 
       plotShadow: false, 
       type: 'pie' 
      }, 
      title: { 
       text: chartData.title 
      }, 
      subtitle: { 
       text: chartData.subtitle 
      }, 
      plotOptions: { 
       pie: { 
        allowPointSelect: true, 
        cursor: 'pointer', 
        dataLabels: { 
         enabled: true, 
         formatter: function() { 
          return Highcharts.numberFormat(Math.round(this.percentage * 100)/100, 1) + '%'; 
         }, 
         distance: -30, 
         color: 'black' 
        }, 
        showInLegend: true 
       } 
      }, 
      noData: { 
       enabled: true 
      }, 
      series: [{ 
       colorByPoint: true, 
       data: chartData.seriesData[0] 
      }] 
     }); 

我在init之后尝试过,但仍选择最后一个片。

 $(divID).highcharts.series[0].data[0].slice(); 

回答

0

Highcharts不会为了你的系列,你可以得到最大再选择这是最大

var chart = $(divID).highcharts; 
var max = Math.max.apply(Math, chart.series[0].data.map(function(v){ 
    return v.y; 
})); 
var maxData = chart.series[0].data.filter(function(v){ 
    if (v.y == max) 
    { 
     return v.y; 
    } 
})[0] 

这里的数据是使用股票选择具有最高值的数据捣鼓饼图http://jsfiddle.net/1zLxnycf/