【问题标题】:How to change colors of the pie chart in d3pie如何在 d3pie 中更改饼图的颜色
【发布时间】:2019-01-22 23:33:52
【问题描述】:

我正在尝试修改以下code 我在网上看到的使用d3pie js 的。我似乎无法弄清楚如何更改颜色?我是 Javascript 的超级新手,想在我的网站上使用这个图表....

g.append("path")
        .attr("id", function(d, i) { return pie.cssPrefix + "segment" + i; })
        .attr("fill", function(d, i) {
            var color = colors[i];
            if (pie.options.misc.gradient.enabled) {
                color = "url(#" + pie.cssPrefix + "grad" + i + ")";
            }
            return color;
        })

有什么线索吗?有点不太明白:(

【问题讨论】:

  • 你可以通过改变颜色数组来改变颜色。请尝试更具体;你想换什么颜色?如果启用渐变,这是有条件地拾取颜色,然后从 url 中选择一些,否则从数组中选择。
  • 是segments数组吗? @Zeeshan

标签: javascript jquery


【解决方案1】:
"data": {
    "content": [
        {
            "label": "Programación",
            "value": 6000,
            "color": "#82ccfb"
        },
        {
            "label": "Blogging",
            "value": 20,
            "color": "#FF0000"
        },
        {
            "label": "Ilustración / Arte",
            "value": 60,
            "color": "#395197"
        },
        {
            "label": "Diseño Gráfico",
            "value": 50,
            "color": "#457cda"
        },
        {
            "label": "Rotulación",
            "value": 20,
            "color": "#b0dae1"
        },
        {
            "label": "Agricultura",
            "value": 10,
            "color": "#062831"
        },
        {
            "label": "Diseño Web",
            "value": 80,
            "color": "#FF0000"
        }
    ]
},

在js文件的末尾。在第 2215 行。检查它。我改变了一些颜色。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-10-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-15
    • 2012-04-17
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多