Skip to content Skip to sidebar Skip to footer

Using Array Values In Chart.js Data And Label Field

I wish to pass values of an array to the data and label fields of the chart.js dataset. Here the code from success of ajax call made to fetch json data. I fetch the json data and s

Solution 1:

LabelResult is an array, change

labels: [LabelResult]

to

labels: LabelResult

Also:

data: [DataResult]

to

data: DataResult

Like:

varmyChart=newChart(ctx, {
    type:'bar',
    data: {
        labels:LabelResult,
        datasets: [{
            label:'# of Votes',
            data:DataResult,
            borderWidth:1
        }]
    }    
});

Solution 2:

I think you could try to remove some brackets.

while(count > 0){
     LabelResult[counter] = Data[counter].TIME; // here removed brackets
      counter++;
      count --;
}    

and

data: {
    labels:LabelResult, //hereremovedbracketsdatasets: [{
        label:'# of Votes',
        data:DataResult, //hereremovedbracketsborderWidth:1
    }]
},

I hope that will works.

Post a Comment for "Using Array Values In Chart.js Data And Label Field"