简体   繁体   English

指定饼图图表的颜色

[英]Specify color for Pie Chart Highchart

I want to specify colors for certain piece for my pie chart. 我想为饼图指定颜色。

I wrote some code like this, but it seems not working. 我写了一些这样的代码,但似乎不起作用。 Anyone got clue how to work around with this? 任何人都知道如何解决这个问题?

{
                name: data[i].status, 
                color: function() {
                    if (data[i].status === "Working") {
                        return '#60a57c';
                    } else if (data[i].status === "Stopped \/ Idle") {
                        return '#e7494d';
                    } else if (data[i].status === "Transport") {
                        return '#fac101';
                    } else if (data[i].status === "Headland Turning") {
                        return '#66cc13';
                    }
                },
                y: data[i].val
            } 

Basically what I want is if the status is "Working" , then we specify color as "#60a57c" , etc. I don't want HighChart auto-generate colors for me. 基本上,我想要的是status"Working" ,我们将颜色指定为"#60a57c"等。我不希望HighChart为我自动生成颜色。

Thank you. 谢谢。

color have to be a string. color必须是字符串。

So try the following: 因此,请尝试以下操作:

var colors = {
    'Working': '#60a57c',
    'Stopped \/ Idle': '#e7494d',
    'Transport': '#fac101',
    'Headland Turning': '#66cc13'
};

var serie = {
    name: data[i].status,
    color: colors[data[i].status],
    y: data[i].val
};

Hope this help you. 希望这对您有所帮助。

Reference 参考

You're setting the color to the function pointer. 您正在将颜色设置为函数指针。 Instead, try defining the function in a separate location and simply calling it to get a color value within your data. 而是尝试在单独的位置定义函数,然后简单地调用它以获取数据中的颜色值。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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