using array values in chart.js data and label field

前端 未结 2 713
鱼传尺愫
鱼传尺愫 2021-01-01 02:34

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

2条回答
  •  北海茫月
    2021-01-01 02:57

    LabelResult is an array, change

    labels: [LabelResult]
    

    to

    labels: LabelResult
    

    Also:

    data: [DataResult]
    

    to

    data: DataResult
    

    Like:

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

提交回复
热议问题