Change the color of bar on condition in highcharts

帅比萌擦擦* 提交于 2019-12-24 12:33:52

问题


I am using highcharts and I want to change the color of bar depending on their Y axis values.

Something like:

{
    color: '#92D050', //DEFAULT COLOR OF CURRENT YEAR BAR ON EACH GROUP
    name: 'AUG',
    shadow: false,
    data: [
       { y: 66, color: '#92D050' },
       { y: 55, color: 'red' },
       { y: 78, color: '#92D050' },
       { y: 55, color: 'red'}
    ]
}

Here how can I apply codition like y: > 60


回答1:


You can iterate for each element and modify SVG parameter like fill.

http://jsfiddle.net/CaPG9/

var max = 200;

$.each(chart.series[0].data,function(i,data){

   if(data.y > max)
       data.graphic.attr({
       fill:'red'
   });

});



回答2:


It doesn't work, cause if you put the mouse over the columns, the color reset for the original.

I solved with this code, using a variable that counts how many columns I want to color. In my case, j is set before to 6.

var j = 6;

$.each(chart.series[0].data, function(i,data){

   for (var n = 0; n <= j; n++) {

      chart.series[0].data[n].update({color:'#441606'});

   }

});


来源:https://stackoverflow.com/questions/16893319/change-the-color-of-bar-on-condition-in-highcharts

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!