根据条件更改条形图的颜色 [英] Change color of barchart based on condition

查看:136
本文介绍了根据条件更改条形图的颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的高智商中有2个系列。 Series1和Series2。在达到某个条件时,它们的颜色会变为红色。我已成功完成了Series2,但不知何故,我也无法改变os Series1的颜色。以下是我的代码:



 $(' #myDiv')。highcharts({
// 逻辑此处
},功能(图表){
var max = 80 ;

$ .each(chart.series [ 2 ]。数据, function (i,data){
if (data.y< max){
data.graphic.attr({
fill:' RED'
});
chart.series [ 0 ]。data [ 0 ]。更新({
marke r:{
fillColor:' RED'
}
} );
}
});
});







如代码所示,系列没有问题[2]数据/颜色变化,但是当我想改变系列[1]的颜色时,它不允许我这样做。

FYI,系列的颜色[1]将改变取决于系列[2]的值,如果系列[2]改变颜色,那么系列[1]将跟随套装。



我尝试了什么:



chart.series [1] .data.graphic.attr({

fill:'RED'

});

解决方案

' #myDiv')。highcharts({
// 逻辑此处
}, function (图表){
var max = 80 ;

.each(chart.series [ 2 ]。data, function (i,data){
if (data.y< max){
data.graphic.attr({
fill:' RED'
});
chart.series [ 0 ]。data [ 0 ]。update({
marker:{
fillColor:' RED'
}
});
}
});
});







如代码所示,系列没有问题[2]数据/颜色变化,但是当我想改变系列[1]的颜色时,它不允许我这样做。

FYI,系列的颜色[1]将改变取决于系列[2]的值,如果系列[2]改变颜色,那么系列[1]将跟随套装。



我尝试了什么:



chart.series [1] .data.graphic.attr({

fill:'RED'

});


检查此 javascript - 在highcharts中动态更改点的颜色 - 堆栈溢出 [ ^ ]


Hi, I have 2 series in my highchart. Series1 and Series2. Upon hitting a condition, their color will change to red. I have successfully done for the Series2 but somehow I cant change the color os Series1 also. Below are my codes:

$('#myDiv').highcharts({
//logics here
            }, function (chart) {
                var max = 80;

                $.each(chart.series[2].data, function (i, data) {
                    if (data.y < max) {
                        data.graphic.attr({
                            fill: 'RED'
                        });
                        chart.series[0].data[0].update({
                            marker: {
                                fillColor: 'RED'
                            }
                        });
                    }
                });
            });




As shown on the codes, there is no problem in series[2] data/color changing but when I want to change the color for series[1], it would not allow me to.
FYI, the color of the series[1] will change depends on the value of series[2], if series[2] changes color, then series[1] will follow suits.

What I have tried:

chart.series[1].data.graphic.attr({
fill: 'RED'
});

解决方案

('#myDiv').highcharts({ //logics here }, function (chart) { var max = 80;


.each(chart.series[2].data, function (i, data) { if (data.y < max) { data.graphic.attr({ fill: 'RED' }); chart.series[0].data[0].update({ marker: { fillColor: 'RED' } }); } }); });




As shown on the codes, there is no problem in series[2] data/color changing but when I want to change the color for series[1], it would not allow me to.
FYI, the color of the series[1] will change depends on the value of series[2], if series[2] changes color, then series[1] will follow suits.

What I have tried:

chart.series[1].data.graphic.attr({
fill: 'RED'
});


Check this javascript - Changing the color of the point dynamically in highcharts - Stack Overflow[^]


这篇关于根据条件更改条形图的颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆