How can I change the colors of my highcharts piechart?

我的未来我决定 提交于 2019-11-28 19:06:05
Highcharts.setOptions({
 colors: ['#50B432', '#ED561B', '#DDDF00', '#24CBE5', '#64E572', '#FF9655', '#FFF263', '#6AF9C4']
});

Look the following example http://jsfiddle.net/8QufV/

I think what you need to do is set the colors using theme instead of setOptions as follows:

Highcharts.theme = {colors: ['#50B432', '#ED561B', '#DDDF00', '#24CBE5', 
                             '#64E572', '#FF9655', '#FFF263', '#6AF9C4']});

For those of you that prefer to initialize the color in the configs, you could simply put the colors in the plotOptions portion of the config object like so:

...,
plotOptions: {
  pie: {
   colors: [
     '#50B432', 
     '#ED561B', 
     '#DDDF00', 
     '#24CBE5', 
     '#64E572', 
     '#FF9655', 
     '#FFF263', 
     '#6AF9C4'
   ],
   allowPointSelect: true,
   cursor: 'pointer',
   dataLabels: {
     enabled: false
   },
   showInLegend: true
 }
},
...

To answer @Loko Web Design's question https://stackoverflow.com/a/38794379/7475250

Is there a webpage that says to what each of the "colors" corresponds? All the answers here show something like:

colors: ['#333', '#CB2326', '#DDDF00', '#24CBE5', '#64E572', '#FF9655', '#CB2326', '#6AF9C4']

But what do #333, #CB2326, etc. actually change? Obviously I can just change them and see what changes, but it would nice to have this reference available somewhere.

The color docs are available here. Although helpful they do not describe what changing a specific color actually does. Below is my best description.

The colors prop gives Highcharts the colors you would like the chart to loop through. For example if you had the following color prop.

colors: ['blue', 'green']

Your pie slices would alternate between blue and green. Changing blue to red your colors would then alternate between red and green. Test it with the following fiddle

Expanding the color list increases the number of colors before repeating.

colors: ['blue', 'green', 'yellow']

Would repeat the colors if more than 4 slices are in your dataset.

min2bro
Highcharts.setOptions({
 colors: ['#333', '#CB2326', '#DDDF00', '#24CBE5', '#64E572', '#FF9655', '#CB2326',      '#6AF9C4']
});

Is there a webpage that says to what each of the "colors" corresponds? All the answers here show something like:

colors: ['#333', '#CB2326', '#DDDF00', '#24CBE5', '#64E572', '#FF9655', '#CB2326', '#6AF9C4']

But what do #333, #CB2326, etc. actually change? Obviously I can just change them and see what changes, but it would nice to have this reference available somewhere.

I had the same problem. In highcharts.css there's a section called "Default colors". After I deleted this section, I could use custom colors. Anyway, I guess you do not need highcharts.css if you use version v5.0.4 or higher.

Highcharts.Color(Highcharts.getOptions().colors[0]).setOpacity(0.5).get('rgba')]

In high charts inbuilt colors we have. So you need to change the path of the color[0] or [1]........[6]

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