我怎样才能在高图中保持颜色不变

How can i keep the color the same in highcharts

本文关键字:颜色 高图中      更新时间:2023-09-26

我第一次使用高图。它看起来很酷,几乎在做我想做的事。我使用一个饼图,每秒钟刷新一次数据。只有作品的颜色每秒都在变化。我怎样才能保持不变的颜色?

这是我的代码

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]
        ]
    }]
});
});

您真的想在饼图中添加新点,还是用新值替换现有点?

如果是后者,您可能需要查看Series setData方法。示例位于http://jsfiddle.net/ebuTs/22/

您尝试过chart.colors选项吗?

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

我认为你需要拥有与数据点相同数量的颜色。似乎对我有用:

http://jsfiddle.net/X9XYK/