简体   繁体   中英

How to change colors of the pie chart in d3pie

I am trying to modify the following code I saw online that uses the d3pie js. I can't seem to figure out how to change the colors? I am super new to Javascript and would like to use this chart on my website....

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

Any clues? Kinda don't understand much :(

"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"
        }
    ]
},

It's at the end of the file in js. At the line number 2215. Check it. I change some colors.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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