javascript JqPlot 饼图 - 更改饼切片颜色

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12476187/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-26 16:16:44  来源:igfitidea点击:

JqPlot Pie Chart - Change Pie Slice Colors

javascriptjqplotpie-chart

提问by 109221793

I have a pie chart displaying using JqPlot. I would be interested in changing the actual colors of the slice, and have had no luck so far.

我有一个使用 JqPlot 显示的饼图。我对更改切片的实际颜色很感兴趣,但到目前为止还没有运气。

I came across this linkand tried the solution, but I'm not sure if I'm putting it in the wrong place (Have tried inserting it in a few locations in the code) as when I have it in, the pie chart no longer displays (and in fact stops the rest of the charts on the page from displaying).

我遇到了这个链接并尝试了解决方案,但我不确定我是否把它放在了错误的地方(尝试将它插入代码中的几个位置),就像我把它放进去一样,饼图没有更长的显示时间(实际上停止显示页面上的其余图表)。

Here is the javascript code for the pie chart:

这是饼图的javascript代码:

$(document).ready(function () {
        var data = [['US',33], ['IE',30], ['GB',23], ['AU',7], ['CA',4], ['RoW',7]];
        var plot1 = jQuery.jqplot('Countries', [data],
        {
            seriesDefaults: {
                // Make this a pie chart.
                renderer: jQuery.jqplot.PieRenderer,
                rendererOptions: {
                    // Put data labels on the pie slices.
                    // By default, labels show the percentage of the slice.
                    sliceMargin: 5,
                    showDataLabels: true,
                }
            },
            legend: { show: true, border: false, /*placement: 'outsideGrid', location: 'w'*/location: 'e', border: 'none' },
            grid: {borderWidth:0, shadow:false, background: '#FFFFFF'}

        }
      );
    });

Does anyone have any ideas?

有没有人有任何想法?

回答by Neil

You can apply seriesColorsto an optionsobject eg:

您可以申请seriesColors一个options对象,例如:

options =
{
    seriesColors: [ "#4bb2c5", "#c5b47f", "#EAA228", "#579575" ]
}

The relevant documentation can be found at jqPlot Options.

相关文档可以在jqPlot 选项中找到