[英]How can I put custom color in High Charts PIE data | Slice and want to change slice text
任何人都可以建议我着色到每张High Charts Data切片。
我的代码在下面也给出了一个图像。 我想将自定义颜色放到每个数据片段(对于数据,如Firefox,Opera,chrome,IE等)。
并且还希望在此示例中删除系列名称('浏览器共享'),如果我将其设为false“name:false”然后显示系列一,我想在Firefox上鼠标悬停时将其显示为“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}: <b>{point.percentage:.1f}%</b>' }, plotOptions: { pie: { allowPointSelect: true, cursor: 'pointer', dataLabels: { enabled: true, format: '<b>{point.name}</b>: {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] ] }] }); });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/highcharts/4.1.5/highcharts.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/highcharts/4.1.5/highcharts-more.src.js"></script> <div id="graph" style="height: 300px; width:100%;"></div>
我们可以指定报告应该如下的默认颜色集:
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: '<b>{point.percentage:.1f}%</b>' // updated tool tip }, plotOptions: { pie: { allowPointSelect: true, cursor: 'pointer', dataLabels: { enabled: true, format: '<b>{point.name}</b>: {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] ] }] }); });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/highcharts/4.1.5/highcharts.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/highcharts/4.1.5/highcharts-more.src.js"></script> <div id="graph" style="height: 300px; width:100%;"></div>
要在工具提示中更改系列名称,您可以更改pointFormat并删除对series.name的引用
例:
tooltip: {
pointFormat: '<b>{point.percentage:.1f}%</b>'
},
小提琴: http : //jsfiddle.net/avsdgek8/
有关颜色,请参阅回答主题
另外:可以为每个数据点设置颜色 - http://jsfiddle.net/avsdgek8/1/或每个系列 - http://api.highcharts.com/highcharts#plotOptions.pie.colors
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.