2012-03-08 26 views
3

我第一次使用highcharts。它看起來很酷,它幾乎正在做我想要的。我使用一個餅圖並每秒刷新一次數據。這只是工作,只是顏色的片斷每秒都在變化。我怎樣才能保持相同的顏色?我如何在高圖中保持顏色相同

這是我的代碼

var chart; 
$(document).ready(function() { 
chart = new Highcharts.Chart({ 
    chart: { 
     renderTo: 'container', 
     plotBackgroundColor: null, 
     animation: false, 
     plotBorderWidth: null, 
     plotShadow: false, 
     events: { 
      load: function() { 

       // set up the updating of the chart each second 
       var series = this.series[0]; 
       setInterval(function() { 
        $.getJSON("opencont.php", function (data) { 
         $.each(data.vragen, function (index, value) { 
         series.addPoint([value.short, value.antwoorden], true, true); 
         }) 
         }) 
       }, 1000); 
      } 
      } 
    }, 
    title: { 
     text: '' 
    }, 
    tooltip: { 
     formatter: function() { 
      return '<b>'+ this.point.name +'</b>: '+ this.percentage +' %'; 
     } 
    }, 
    plotOptions: { 
     pie: { 
      allowPointSelect: true, 
      cursor: 'pointer', 
      dataLabels: { 
       enabled: true, 
       color: '#000000', 
       connectorColor: '#000000', 
       formatter: function() { 
        return '<b>'+ this.point.name +'</b>: '+ this.percentage +' %'; 
       } 
      } 
     } 
    }, 


    series: [{ 
     type: 'pie', 
     name: 'Browser share', 
     data: [ 
     ['a', 0], ['b', 0], ['c', 0] 
     ] 
    }] 
}); 
}); 
+0

它已經在這裏找到答案http://stackoverflow.com/questions/17802509/how-can-i-reset-the-styles-given-to-series-in-highcharts – Aximili 2016-10-13 03:27:08

回答

1

你真的想新的點添加到餅圖,或者你想用新值替換現有的點?

如果是更高版本,則可能需要查看Series setData方法。例如在http://jsfiddle.net/ebuTs/22/

0

您是否嘗試過的chart.colors選項?

http://www.highcharts.com/ref/#colors

我相信你需要有相同數量的顏色數據點。似乎爲我工作:

http://jsfiddle.net/X9XYK/

+0

是的,我試過: Highcharts .setOptions({0#顏色:['#058DC7','#50B432','#ED561B'] }); 但仍然不斷改變顏色 – 2012-03-08 09:09:46

相關問題