javascript - How to set color of each slice in pie chart in high charts library? -


i making pie chart high chart library. want change color of each slice in pie chart how can ? code -

var colors = ["color:'#2a8482'","color:'#64decf'","color:'#bccdf8'"];  var responsedata = {"2":40,"1":30} var obj =  $.parsejson(responsedata);              var dataarrayfinal = array();              var value = array();              var name = array();              var j = 0;              (var key in obj) {                   if (obj.hasownproperty(key)) {                       name[j] =  "name:'"+key+"'";                       value[j] = obj[key];                       j++;                   }              }               for(k=0;k<name.length;k++) {                     var temp = new array(name[k],value[k],colors[k]);                     dataarrayfinal[k] = temp;                   }              $(function () {                  new highcharts.chart({                     chart: {                         renderto: 'container'+counter,                         type: 'pie',                         height: 280,                         width: 280                     },                     title: {                         text: ' '                     },                     tooltip: {                         valuesuffix: '%',                         positioner: function () {                             return {                                 x: this.chart.series[0].center[0] -                                    (this.label.width / 2) + 8,                                 y: this.chart.series[0].center[1] -                                    (this.label.height / 2) + 8                             };                         }                     },                     series: [{                         name: 'answer',                         size: '100%',                         innersize: '65%',                         data: dataarrayfinal                     }]                 });             }); 

in graph coming colors not changed. taking default color.

enter image description here

if change color-array to:

var colors = ["#2a8482","#64decf","#bccdf8"];

and @ beginning of function:

$(function () { 

add following code:

highcharts.getoptions().plotoptions.pie.colors = colors; 

this should trick.

example of coloring can found in jsfiddle, created developers of highcharts: http://jsfiddle.net/gh/get/jquery/1.7.2/highslide-software/highcharts.com/tree/master/samples/highcharts/demo/pie-monochrome/


Comments

Popular posts from this blog

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

linux - disk space limitation when creating war file -

How to provide Authorization & Authentication using Asp.net, C#? -