2017-03-02 2 views
0

Ich versuche, Etiketten zu meinem Balkendiagramm hinzuzufügen. Siehe JS Geige und Code unten. Wie würde ich meinen Code ändern, um Labels hinzuzufügen?Labels zu ChartsJS hinzufügen Balkendiagramm

http://jsfiddle.net/amwmedia/8kqvyhqv/

var myNewChart; 
var data = [ 
    { 
    value: 30, 
    label: "hello", 
    color: "#F7464A" 
    }, { 
    value: 50, 
    color: "#E2EAE9" 
    }, { 
    value: 100, 
    color: "#D4CCC5" 
    }, { 
    value: 40, 
    color: "#949FB1" 
    }, { 
    value: 100, 
    color: "#4D5360" 
    }, 

]; 


var options = { 
    animation: true, 
    animationEasing: 'easeInOutQuart', 
    animationSteps: 80, 
    multiTooltipTemplate: "<%= datasetLabel %> - <%= value %>" 

}; 


var ctx = document.getElementById("myChart") 
            .getContext("2d"); 

myNewChart = new Chart(ctx).Doughnut(data, options); 
+0

Mögliches Duplikat von [Wie fügt man Beschriftungen in das Chart.js-Canvas-Plugin ein?] (http://StackOverflow.com/questions/16590301/how-to-add-labels-into chart-js-canvas-plugin) – nico

+0

Es ist sicher ein Duplikat von [Wie man Kreisdiagrammdatenwerte jedes Slices in chart.js anzeigt] (http://stackoverflow.com/questions/33363373/how-to- display-pie-chart-daten-werte-von-jedem-slice-in-chart-js) – jordanwillis

Antwort

1

bemerkte ich Ihre jsfiddle ist chart.js Version 1. Meine Antwort verwendet Version 2 verwenden, wie alles, was ich Dokumentation finden.

Sieht aus wie alles, was Sie tun müssen, Etiketten in dem Datenobjekt gesetzt wird:

var data = { 
    labels: [ 
    "label1", 
    "label2", 
    "label3", 
    "label4", 
    "label5" 
    ], 
    datasets: [ 
    { 
    data: [ 
    30, 
    50, 
    100, 
    40, 
    100 
    ], 
    backgroundColor:[ 
    '#F7464A', 
    '#E2EAE9', 
    '#D4CCC5', 
    '#949FB1', 
    '#4D5360' 
    ] 
    }] 
}; 

fiddle See. (Dies verwendet Chart.js 2.0)

+0

Perfekt! Vielen Dank! – AndrewLeonardi

Verwandte Themen