如何在High Charts PIE数据中添加自定义颜色| 切片并想要更改切片文本
任何人都可以建议我着色到每张High Charts Data切片。
我的代码在下面也给出了一个图像。 我想将自定义颜色放到每个数据片段(对于数据,如Firefox,opera,chrome,IE等…)
并且还希望在此示例中删除系列名称(’浏览器共享’),如果我将其设为false“name:false”然后显示系列一,我想在Firefox上鼠标hover时将其显示为“Firefox:45%”切片
$(function () { $('#graph').highcharts({ chart: { plotBackgroundColor: null, plotBorderWidth: null, plotShadow: false }, title: { text: 'Browser market shares at a specific website, 2014' }, tooltip: { pointFormat: '{series.name}: {point.percentage:.1f}%' }, plotOptions: { pie: { allowPointSelect: true, cursor: 'pointer', dataLabels: { enabled: true, format: '{point.name}: {point.percentage:.1f} %', style: { color: (Highcharts.theme && Highcharts.theme.contrastTextColor) || 'black' } } } }, series: [{ type: 'pie', name: 'Browser share', data: [ ['Firefox', 45.0], ['IE', 26.8], { name: 'Chrome', y: 12.8, sliced: true, selected: true }, ['Safari', 8.5], ['Opera', 6.2], ['Others', 0.7] ] }] }); });
我们可以指定报告应该如下的默认颜色集:
Highcharts.getOptions().plotOptions.pie.colors=['#2f7ed8', '#0d233a', '#8bbc21', '#910000', '#1aadce', '#492970', '#f28f43', '#77a1e5', '#c42525', '#a6c96a'];
$(function () { //Specify color set as follows Highcharts.getOptions().plotOptions.pie.colors=['#2f7ed8', '#0d233a', '#8bbc21', '#910000', '#1aadce', '#492970', '#f28f43', '#77a1e5', '#c42525', '#a6c96a']; $('#graph').highcharts({ chart: { plotBackgroundColor: null, plotBorderWidth: null, plotShadow: false }, title: { text: 'Browser market shares at a specific website, 2014' }, tooltip: { pointFormat: '{point.percentage:.1f}%' // updated tool tip }, plotOptions: { pie: { allowPointSelect: true, cursor: 'pointer', dataLabels: { enabled: true, format: '{point.name}: {point.percentage:.1f} %', style: { color: (Highcharts.theme && Highcharts.theme.contrastTextColor) || 'black' } } } }, series: [{ type: 'pie', name: 'Browser share', data: [ ['Firefox', 45.0], ['IE', 26.8], { name: 'Chrome', y: 12.8, sliced: true, selected: true }, ['Safari', 8.5], ['Opera', 6.2], ['Others', 0.7] ] }] }); });
要在工具提示中更改系列名称,您可以更改pointFormat并删除对series.name的引用
例:
tooltip: { pointFormat: '{point.percentage:.1f}%' },
小提琴: http : //jsfiddle.net/avsdgek8/
有关颜色,请参阅回答主题
highcharts:在饼图中动态定义颜色
如何更改highcharts饼图的颜色?
另外:可以为每个数据点设置颜色 – http://jsfiddle.net/avsdgek8/1/或每个系列 – http://api.highcharts.com/highcharts#plotOptions.pie.colors