简体   繁体   中英

How can i keep the color the same in highcharts

i am using highcharts for the first time. It looks cool and it is almost doing what i want. I use a piechart and refresh the data every second. That is working only the color of the pieces are changing 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]
        ]
    }]
});
});

Do you really want to add new points to the Pie chart, or do you want to replace the existing points with new values?

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

Have you tried the chart.colors option?

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

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

http://jsfiddle.net/X9XYK/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM