gpt4 book ai didi

json - Highcharts 根据值动态更改条形颜色

转载 作者:行者123 更新时间:2023-12-04 13:08:00 25 4
gpt4 key购买 nike

我正在使用json数据创建列类型图。这是我调用的JS函数,用于使用ajax调用获取数据并绘制图表。

function getChart(){
var categorySeries = [];
var dataSeries = [];
var url = "CallToControllerURL";

$.getJSON(url, function(response) {
$.each(response, function(i, item) {
categorySeries .push(response[i].dateVal);
dataSeries.push(response[i].count);
});

$('#chartDiv').highcharts({
chart : {type : 'column'},
title : {text : 'Date vs Count'},
xAxis : {categories : categorySeries, crosshair : true},
yAxis : {allowDecimals: false, min : 0, title : { text : 'Count'}},
plotOptions : { column : { pointPadding : 0.2, borderWidth : 0, allowPointSelect: true } },
series : [ {name : 'Nbr of Records',data : dataSeries } ]
});
});
}

如果计数大于特定值(例如10),我希望能够在一天中修改条形的颜色。

这就是json输入到函数的方式。
[{"id":3,"dateVal":"2015-11-12","count":6},{"id":2,"dateVal":"2015-11-11","count":8},{"id":1,"dateVal":"2015-11-10","count":5}]

有什么建议我可以做到这一点吗?

最佳答案

您可以使用颜色区域(API)根据列的值使用不同的颜色。

值低于10或高于10的示例具有不同的颜色(JSFiddle):

plotOptions: {
column: {
zones: [{
value: 10, // Values up to 10 (not including) ...
color: 'blue' // ... have the color blue.
},{
color: 'red' // Values from 10 (including) and up have the color red
}]
}
}

关于json - Highcharts 根据值动态更改条形颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34800720/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com