简体   繁体   English

如何在High Charts PIE数据中添加自定义颜色| 切片并想要更改切片文本

[英]How can I put custom color in High Charts PIE data | Slice and want to change slice text

Can anyone suggest me about colouring to each slice of High Charts Data. 任何人都可以建议我着色到每张High Charts Data切片。

My Code is given below also a image there. 我的代码在下面也给出了一个图像。 I want to put my custom color to each slice of data (for data are like Firefox, opera, chrome, IE etc.. ) 我想将自定义颜色放到每个数据片段(对于数据,如Firefox,Opera,chrome,IE等)。

and also want to remove series name ('Browser share') in this example, if I put it false "name: false" then is showing series one, I want to show it like "Firefox: 45%" on mouse hover on Firefox slice 并且还希望在此示例中删除系列名称('浏览器共享'),如果我将其设为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> 

在此输入图像描述

We can specify default color set which the report should as follows: 我们可以指定报告应该如下的默认颜色集:

 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> 

To change series name in tooltip you can change pointFormat and remove reference to series.name 要在工具提示中更改系列名称,您可以更改pointFormat并删除对series.name的引用

Example: 例:

 tooltip: {
            pointFormat: '<b>{point.percentage:.1f}%</b>'
        },

Fiddle: http://jsfiddle.net/avsdgek8/ 小提琴: http//jsfiddle.net/avsdgek8/

For colors see answered topics: 有关颜色,请参阅回答主题

highcharts: dynamically define colors in pie chart highcharts:在饼图中动态定义颜色

How can I change the colors of my highcharts piechart? 如何更改highcharts饼图的颜色?

Also: color can be set per data point - http://jsfiddle.net/avsdgek8/1/ or per series - http://api.highcharts.com/highcharts#plotOptions.pie.colors 另外:可以为每个数据点设置颜色 - http://jsfiddle.net/avsdgek8/1/或每个系列 - http://api.highcharts.com/highcharts#plotOptions.pie.colors

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM