Javascript 如何动态更改Highchart列的颜色
我想根据平均值或限制值设置highchart列的颜色。例如,限制值为%20,超过%20的列将显示红色,低于20%的列将显示绿色 图表显示:Javascript 如何动态更改Highchart列的颜色,javascript,highcharts,Javascript,Highcharts,我想根据平均值或限制值设置highchart列的颜色。例如,限制值为%20,超过%20的列将显示红色,低于20%的列将显示绿色 图表显示: function GetEnduktiveKapasitiveValues(type) { $.ajax({ url: app_base_url + "Reactive/_ReaktiveDaily", type: 'POST', data: { branchId: 9, dateMonth: 3, type: type },
function GetEnduktiveKapasitiveValues(type) {
$.ajax({
url: app_base_url + "Reactive/_ReaktiveDaily",
type: 'POST',
data: { branchId: 9, dateMonth: 3, type: type },
success: function (result) {
var list = [];
$.each(result.DateList, function (i, val) {
var value = new Date(parseInt(val.substr(6)));
var month = value.getMonth() + 1;
var ret = value.getDate() + "." + month + "." + value.getFullYear();
list[i] = ret;
});
$('#container').highcharts({
chart: {
type: 'column'
},
title: {
text: 'Günlük Endüktif - Kapasitif Ceza Limiti Değerleri'
},
subtitle: {
text: ''
},
xAxis: {
categories: list
},
yAxis: {
min: 0,
title: {
text: 'Oran (%)'
}
},
tooltip: {
headerFormat: '<span style="font-size:10px">{point.key}</span><table>',
pointFormat: '<tr><td style="color:{series.color};padding:0">{series.name}: </td>' +
'<td style="padding:0"><b>{point.y:.1f} mm</b></td></tr>',
footerFormat: '</table>',
shared: true,
useHTML: true
},
credits: {
enabled: false
},
plotOptions: {
column: {
pointPadding: 0.2,
borderWidth: 0,
borderRadius: 20
},
color : ['#333', '#CB2326', '#DDDF00', '#24CBE5', '#64E572', '#FF9655', '#CB2326', '#6AF9C4']
},
series: [{
name: result.Name,
data: result.RateList,
type: 'column'
}, {
name: 'Ceza Limiti',
type: 'line',
data: result.Average,
marker: {
lineWidth: 2,
lineColor: Highcharts.getOptions().colors[3],
fillColor: 'white'
}
}]
});
},
error: function (result) { }
});
}
脚本:
function GetEnduktiveKapasitiveValues(type) {
$.ajax({
url: app_base_url + "Reactive/_ReaktiveDaily",
type: 'POST',
data: { branchId: 9, dateMonth: 3, type: type },
success: function (result) {
var list = [];
$.each(result.DateList, function (i, val) {
var value = new Date(parseInt(val.substr(6)));
var month = value.getMonth() + 1;
var ret = value.getDate() + "." + month + "." + value.getFullYear();
list[i] = ret;
});
$('#container').highcharts({
chart: {
type: 'column'
},
title: {
text: 'Günlük Endüktif - Kapasitif Ceza Limiti Değerleri'
},
subtitle: {
text: ''
},
xAxis: {
categories: list
},
yAxis: {
min: 0,
title: {
text: 'Oran (%)'
}
},
tooltip: {
headerFormat: '<span style="font-size:10px">{point.key}</span><table>',
pointFormat: '<tr><td style="color:{series.color};padding:0">{series.name}: </td>' +
'<td style="padding:0"><b>{point.y:.1f} mm</b></td></tr>',
footerFormat: '</table>',
shared: true,
useHTML: true
},
credits: {
enabled: false
},
plotOptions: {
column: {
pointPadding: 0.2,
borderWidth: 0,
borderRadius: 20
},
color : ['#333', '#CB2326', '#DDDF00', '#24CBE5', '#64E572', '#FF9655', '#CB2326', '#6AF9C4']
},
series: [{
name: result.Name,
data: result.RateList,
type: 'column'
}, {
name: 'Ceza Limiti',
type: 'line',
data: result.Average,
marker: {
lineWidth: 2,
lineColor: Highcharts.getOptions().colors[3],
fillColor: 'white'
}
}]
});
},
error: function (result) { }
});
}
函数GetEndUktivekCapativeValues(类型){
$.ajax({
url:app_base_url+“Reactive/_ReaktiveDaily”,
键入:“POST”,
数据:{branchId:9,dateMonth:3,type:type},
成功:功能(结果){
var列表=[];
$.each(result.DateList,function(i,val){
var值=新日期(parseInt(val.substr(6));
var month=value.getMonth()+1;
var ret=value.getDate()+“+月+”+value.getFullYear();
列表[i]=ret;
});
$(“#容器”)。高图({
图表:{
类型:“列”
},
标题:{
文本:“Günlük Endüktif-Kapasitif Ceza Limiti Değerleri”
},
副标题:{
文本:“”
},
xAxis:{
类别:列表
},
亚克斯:{
分:0,,
标题:{
文本:“Oran(%)”
}
},
工具提示:{
headerFormat:“{point.key}”,
pointFormat:“{series.name}:”+
“{point.y:.1f}mm”,
页脚格式:“”,
分享:是的,
useHTML:true
},
学分:{
已启用:false
},
打印选项:{
专栏:{
点填充:0.2,
边框宽度:0,
边界半径:20
},
颜色:['#333'、'#CB2326'、'#DDDF00'、'#24CBE5'、'#64E572'、'#FF9655'、'#CB2326'、'#6AF9C4']
},
系列:[{
name:result.name,
数据:result.RateList,
类型:“列”
}, {
名称:“Ceza Limiti”,
键入:“行”,
数据:结果,平均值,
标记:{
线宽:2,
lineColor:Highcharts.getOptions().Color[3],
填充颜色:“白色”
}
}]
});
},
错误:函数(结果){}
});
}
我想得到这样的结果:
您可以通过指定数据中的颜色来完成此操作。e、 g.从highcharts示例中:
data: [29.9, 71.5, 106.4, 129.2, 144.0, 176.0, 135.6, 148.5, {
y: 216.4,
color: '#BF0B23'
}, 194.1, 95.6, 54.4]
- 创建一个临时系列对象李>
- 然后在数据中循环并根据您的值指定
数据。为
添加颜色,并将其推送到series数据对象李>
- 循环完成后,将temp series对象推送到hightchart选项系列
这个例子是一个简单的演示。您需要根据需要对其进行调整。我将如何使用y值为y>216或y<216@SteveP的条件?