我有代码在哪里可以工作,但仅限于图表类型“列”。
像这样http://jsfiddle.net/Blooder/02bncux6
<div id="first">
</div>
<button id="but">Change to red</button>
$(document).ready(function(){
loadBarChart();
$("#but").on("click",function() {
var series = chart.highcharts().series[2];
series.update({
color: 'red'
});
});
});
function loadBarChart(){
chart = $('<div class="widget barchart"></div>');
$("#first").append(chart);
chart.highcharts({
chart: {
type: 'column'
},
title: {
text: ""
},
credits: {
enabled: false
},
legend: {
enabled: false
},
xAxis: {
categories: ['33%', '66%', '100%']
},
yAxis: {
title: {
text: null
}
},
series: [{
name: 'Year 1800',
data: [107, 31, 635, 203, 2]
}, {
name: 'Year 1900',
data: [133, 156, 947, 408, 6]
}, {
name: 'Year 2000',
data: [814, 841, 3714, 727, 31]
}, {
name: 'Year 2016',
data: [1216, 1001, 4436, 738, 40]
}]
});
}
但是当您尝试将此类型更改为图表 Pie 时,这是行不通的。请问我该如何解决?
饼图类型只有一个系列,因此要更改颜色,您必须update
在一个点上使用方法:
$("#but").on("click", function() {
var point = chart.series[0].points[1];
point.update({
color: 'red'
});
});
现场演示:https : //jsfiddle.net/BlackLabel/tLk65vf8/
文档:https : //www.highcharts.com/docs/chart-and-series-types/pie-chart
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句