2016-08-09 39 views
-1

Wie kann ich die Etiketten haben die gleiche Farbe von jeder Scheibe auf Donut-Diagramm mit nvd3?Wie ändert man Etiketten Farben auf einem Donut-Diagramm mit nvd3?

Example image

+0

möglich Duplikat http://stackoverflow.com/questions/33802750/how-to-change-color-of-donut-chart-created-using-d3-js –

+0

nein, es ist nicht. Ich finde heraus, wie man die Schnittfarbe ändert, aber nicht wie man die Etikettenfarbe ändert –

+0

hilft das andere? http://stackoverflow.com/questions/18874877/how-do-i-color-labels-for-my-pie-chart-in-d3 –

Antwort

0

Verstanden!

var colors = ["#eb5945", "#f8e71c", "#67c60b"]; 
nv.addGraph(function() { 
var chart = nv.models.pieChart() 
    .x(function(d) { return d.label }) 
    .y(function(d) { return d.value }) 
    .showLabels(true) 
    .showLegend(false) 
    .labelThreshold(.05) 
    .tooltips(false) 
    .color(colors) 
    .donutLabelsOutside(true) 
    .donut(true) 
    .donutRatio(0.7); 

    d3.select("#chart svg") 
     .datum(data) 
     .transition().duration(1200) 
     .call(chart); 

    d3.selectAll('.nv-label text') 
     .each(function(d,i){ 
     d3.select(this).style('fill',colors[i]) 
     d3.select(this).style('font-weight', 700) 
     d3.select(this).style('font-size', 16) 
    }) 

    return chart; 
});