Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Changing series color in highcharts dynamically

I have been able to change the stroke color on a spline graph, but the points and the legend do not change color until after I hide and show the series by clicking it and then mousing over each of the points.

I have a fiddle here: http://jsfiddle.net/J56hm/2/

$(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].color = "#FF0000";
        chart.series[0].graph.attr({ stroke: '#FF0000' });

        $.each(chart.series[0].data, function(i, point) {
           point.graphic.attr({ fill: '#FF0000' });
         });
        chart.series[0].redraw();
        chart.redraw();
    });
});​

Any idea why this is happening or a way to work around this?

like image 631
Soliah Avatar asked Sep 14 '12 07:09

Soliah


People also ask

How do I change colors in Highcharts?

To change the background color of the chart you have to set in the chart. backgroundColor property. Bar colors in the series color property. Check the example with your chart I posted below.

Is it possible to pass multiple series in a chart in Highcharts?

Yes, you can.

Is Highcharts a JavaScript library?

Highcharts, the core library of our product suite, is a pure JavaScript charting library based on SVG that makes it easy for developers to create responsive, interactive and accessible charts. Our library includes all the standard chart types and more.

How do I change height in Highcharts?

use chart. setSize(width, height, doAnimation = true); in your actual resize function to set the height and width dynamically. Set reflow: false in the highcharts-options and of course set height and width explicitly on creation.


1 Answers

it's simple, you can use this code

chart.series[0].options.color = "#008800";
chart.series[0].update(chart.series[0].options);
like image 83
Duc Anh Nguyen Avatar answered Sep 21 '22 18:09

Duc Anh Nguyen