2012-09-18 127 views
5

我有一个饼图显示使用JqPlot。我会有兴趣改变切片的实际颜色,迄今为止还没有运气。JqPlot饼图 - 更改饼切片颜色

我遇到了this link并尝试了解决方案,但我不确定是否将它放在错误的位置(试图在代码中的几个位置插入它),因为当我有它时,饼图不再显示(实际上停止显示页面上的其他图表)。

下面是饼图的JavaScript代码:

$(document).ready(function() { 
     var data = [['US',33], ['IE',30], ['GB',23], ['AU',7], ['CA',4], ['RoW',7]]; 
     var plot1 = jQuery.jqplot('Countries', [data], 
     { 
      seriesDefaults: { 
       // Make this a pie chart. 
       renderer: jQuery.jqplot.PieRenderer, 
       rendererOptions: { 
        // Put data labels on the pie slices. 
        // By default, labels show the percentage of the slice. 
        sliceMargin: 5, 
        showDataLabels: true, 
       } 
      }, 
      legend: { show: true, border: false, /*placement: 'outsideGrid', location: 'w'*/location: 'e', border: 'none' }, 
      grid: {borderWidth:0, shadow:false, background: '#FFFFFF'} 

     } 
    ); 
    }); 

有没有人有什么想法?

+1

看看seriesColors - http://www.jqplot.com/docs/ files/jqPlotOptions-txt.html – Neil

+1

@Neil完美的工作。你想把你的链接作为答案,我会把它标记为正确的? – 109221793

回答

16

您可以将seriesColorsoptions对象如:

options = 
{ 
    seriesColors: [ "#4bb2c5", "#c5b47f", "#EAA228", "#579575" ] 
} 

相关文件,可以发现在jqPlot Options.

+1

对我有用..谢谢 – andy

+0

只需稍加说明,jqPlot文档的“选项”部分有时可能会过期。检查标题中是否有任何提供警告的内容。 – Bern

+0

不幸的是,你不能将这种颜色设置为“透明”... –