如何在highcharts中保持颜色相同

时间:2012-03-08 08:29:11

标签: javascript highcharts styling

我第一次使用highcharts。它看起来很酷,它几乎正在做我想要的。我使用饼图并每秒刷新数据。这只是作品的颜色每秒都在变化。我怎样才能保持相同的颜色?

这是我的代码

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

2 个答案:

答案 0 :(得分:1)

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

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

上的示例

答案 1 :(得分:0)

您是否尝试过chart.colors选项?

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

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

http://jsfiddle.net/X9XYK/