Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/394.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 我怎样才能在图表中保持相同的颜色_Javascript_Highcharts_Styling - Fatal编程技术网

Javascript 我怎样才能在图表中保持相同的颜色

Javascript 我怎样才能在图表中保持相同的颜色,javascript,highcharts,styling,Javascript,Highcharts,Styling,我第一次使用海图。它看起来很酷,几乎可以满足我的需求。我使用piechart并每秒刷新数据。这是可行的,只是每秒钟都会改变一件作品的颜色。我怎样才能保持相同的颜色 这是我的密码 var chart; $(document).ready(function() { chart = new Highcharts.Chart({ chart: { renderTo: 'container', plotBackgroundColor: null, a

我第一次使用海图。它看起来很酷,几乎可以满足我的需求。我使用piechart并每秒刷新数据。这是可行的,只是每秒钟都会改变一件作品的颜色。我怎样才能保持相同的颜色

这是我的密码

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]
        ]
    }]
});
});
var图;
$(文档).ready(函数(){
图表=新的高点图表。图表({
图表:{
renderTo:'容器',
plotBackgroundColor:null,
动画:错,
plotBorderWidth:null,
影子:错,
活动:{
加载:函数(){
//设置图表的每秒更新
var系列=本系列[0];
setInterval(函数(){
$.getJSON(“opencont.php”,函数(数据){
$.each(data.vragen,函数(索引,值){
series.addPoint([value.short,value.antwoorden],true,true);
})
})
}, 1000);
}
}
},
标题:{
文本:“”
},
工具提示:{
格式化程序:函数(){
返回“+this.point.name+”:“+this.percentage+”%”;
}
},
打印选项:{
馅饼:{
allowPointSelect:true,
光标:“指针”,
数据标签:{
启用:对,
颜色:'#000000',
连接器颜色:'#000000',
格式化程序:函数(){
返回“+this.point.name+”:“+this.percentage+”%”;
}
}
}
},
系列:[{
键入“pie”,
名称:“浏览器共享”,
数据:[
[a',0],[b',0],[c',0]
]
}]
});
});

您是否尝试过chart.colors选项

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


是否确实要将新点添加到饼图中,还是要用新值替换现有点


如果是后者,您可能需要查看Series setData方法。在

yes的示例中,我尝试了:Highcharts.setOptions({colors:[''058DC7','50B432','ED561B']});但颜色还是在不断变化这里已经有答案了