How can I keep the color the same in highcharts

I am using highcharts for the first time. It looks cool and I almost do what I want. I am using piechart and am updating the data every second. This works only the color of the parts changes every second. How can I keep the same color?

This is my code

var chart;
$(document).ready(function() {
chart = new Highcharts.Chart({
    chart: {
        renderTo: 'container',
        plotBackgroundColor: null,
        animation: false,
        plotBorderWidth: null,
        plotShadow: false,
        events: {
            load: function() {

                // set up the updating of the chart each second
                var series = this.series[0];
                setInterval(function() {
                    $.getJSON("opencont.php", function (data) {
                        $.each(data.vragen, function (index, value) {
                        series.addPoint([value.short, value.antwoorden], true, true);
                        })
                        })
                }, 1000);
            }
            }
    },
    title: {
        text: ''
    },
    tooltip: {
        formatter: function() {
            return '<b>'+ this.point.name +'</b>: '+ this.percentage +' %';
        }
    },
    plotOptions: {
        pie: {
            allowPointSelect: true,
            cursor: 'pointer',
            dataLabels: {
                enabled: true,
                color: '#000000',
                connectorColor: '#000000',
                formatter: function() {
                    return '<b>'+ this.point.name +'</b>: '+ this.percentage +' %';
                }
            }
        }
    },


    series: [{
        type: 'pie',
        name: 'Browser share',
        data: [
        ['a', 0], ['b', 0], ['c', 0]
        ]
    }]
});
});

      

+3


source to share


2 answers


Are you sure you want to add new points to the pie chart, or do you want to replace existing points with new values?



If it's later, you can look at the setData method. Example at http://jsfiddle.net/ebuTs/22/

+1


source


Have you tried the chart.colors variant?

http://www.highcharts.com/ref/#colors



I believe you need to have the same number of colors as the data points. Seems to work for me:

http://jsfiddle.net/X9XYK/

0


source







All Articles