我正在使用json数据创建列类型图.这是我使用ajax调用获取数据并绘制图表的JS函数.
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 } ]
});
});
}
Run Code Online (Sandbox Code Playgroud)
如果计数大于特定值,我想能够修改任何一天的条形颜色,比如说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}]
Run Code Online (Sandbox Code Playgroud)
有什么建议我怎么做到这一点?
Hal*_*and 18
您可以根据列的值使用颜色区域(API)来使用不同的颜色.
值低于/高于值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
}]
}
}
Run Code Online (Sandbox Code Playgroud)