javascript 在 highcharts 中动态更改点的颜色

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16286640/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-27 04:04:34  来源:igfitidea点击:

Changing the color of the point dynamically in highcharts

javascriptjsonhighcharts

提问by Sandeep

I have been able to change the color of point in a graph dynamically, but when I hover over that point then the color of that point is changing to previous color.

我已经能够动态更改图表中点的颜色,但是当我将鼠标悬停在该点上时,该点的颜色会更改为以前的颜色。

I have a fiddle here: jfiddle

我这里有一个小提琴: jfiddle

$(function () {
var chart = new Highcharts.Chart({
    chart: {
        renderTo: 'container'
    },
    xAxis: {
        categories: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
    },

    series: [{
        data: [29.9, 71.5, 106.4, 129.2, 144.0, 176.0, 135.6, 148.5, 216.4, 194.1, 95.6, 54.4]        
    }]
});

// the button handler
$('#button').click(function() {

    chart.series[0].data[2].graphic.attr({ fill: '#FF0000' });        
    chart.redraw();
});

How can I change the color of the point dynamically in a graph?

如何在图形中动态更改点的颜色?

回答by Strikers

I think you are looking to update the marker color dynamically.

我认为您正在寻找动态更新标记颜色。

you can use update functionality for this

您可以为此使用更新功能

chart.series[0].data[0].update();

Here is a jsFiddlefor your reference. I hope this will be useful for you.

这是一个jsFiddle供您参考。我希望这对你有用。