Javascript Highcharts-柱形图:比较相应的值以更改颜色
我想设置一个固定放置列集,在其中比较相应的系列数据,如果一个片段的趋势低于基线,则颜色将改变 例如,在这里看到的默认固定放置列集合上: })) 在西雅图总部,由于Employees Optimized的趋势在Employees列下方,因此我希望根据两个系列之间相应数据之间的值,将Employees Optimized的颜色动态更改为绿色 基本上,如果xJavascript Highcharts-柱形图:比较相应的值以更改颜色,javascript,highcharts,Javascript,Highcharts,我想设置一个固定放置列集,在其中比较相应的系列数据,如果一个片段的趋势低于基线,则颜色将改变 例如,在这里看到的默认固定放置列集合上: })) 在西雅图总部,由于Employees Optimized的趋势在Employees列下方,因此我希望根据两个系列之间相应数据之间的值,将Employees Optimized的颜色动态更改为绿色 基本上,如果x
非常感谢您的帮助。您有两个选择。您可以预处理数据,并在
数据
数组中附加颜色属性,使其看起来像:
{
name: 'Employees Optimized',
color: 'rgba(126,86,134,.9)',
data: [{y: 140, color: 'green'}, 90, 40],
pointPadding: 0.4,
pointPlacement: -0.2
}
也可以使用该函数动态指定颜色。在该函数中,您可以循环查看系列数据点(假设您正在查看“员工优化”,即系列[1]
)。然后将每个点与系列[0]
(“员工”)中的相同索引点进行比较。然后,如果满足条件,则更新点的颜色。下面是一个非常详细的方法:
events: {
load: function (event) {
var theSeries = this.series[1];
var theCompSeries = this.series[0];
var theData = theSeries.data;
var theCompData = theCompSeries.data;
for (var i = 0; i < theData.length; i++) {
var theDataPoint = theData[i].y
var theCompDataPoint = theCompData[i].y;
if (theData[i].y < theCompData[i].y) {
console.log(theSeries);
theSeries.points[i].update({
color: 'green'
});
}
}
}
}
事件:{
加载:函数(事件){
var theSeries=本系列[1];
var theCompSeries=this.series[0];
var theData=系列数据;
var theCompData=compseries.data;
对于(变量i=0;i
现场正如我所说,非常详细;)。
events: {
load: function (event) {
var theSeries = this.series[1];
var theCompSeries = this.series[0];
var theData = theSeries.data;
var theCompData = theCompSeries.data;
for (var i = 0; i < theData.length; i++) {
var theDataPoint = theData[i].y
var theCompDataPoint = theCompData[i].y;
if (theData[i].y < theCompData[i].y) {
console.log(theSeries);
theSeries.points[i].update({
color: 'green'
});
}
}
}
}