简体   繁体   English

如何将Json数据设置为chart.js栏

[英]How to set Json data to chart.js bar

How to set json data to labels for Chart.js? 如何将json数据设置为Chart.js的标签?

I have tried setting the array, customer formatted the string but for some reason its not working. 我尝试设置数组,客户对字符串进行了格式化,但由于某种原因其无法正常工作。 Any help is highly appreciated. 非常感谢您的帮助。

var temp = "a,b,c,d";
var reportdata = [];
var labels = [];
while (i < temp.split(",")) {
                        labels.push(temp[i].toString());
                        i += 1;
                    }

var data = {
                        labels: labels,
                        datasets: [
                            {
                                label: "",
                                fillColor: "rgba(220,220,220,0.5)",
                                strokeColor: "rgba(220,220,220,0.8)",
                                highlightFill: "rgba(220,220,220,0.75)",
                                highlightStroke: "rgba(220,220,220,1)",
                                data: reportdata
                            }
                        ]
                    };

Thank you in advance. 先感谢您。

to start with, 'split' creates an array, so you don't have to push the results of 'split' into a new array, just: 首先,“拆分”将创建一个数组,因此您不必将“拆分”的结果推入新数组,只需:

var temp = "a,b,c,d";
var labels = temp.split(",");

now labels[1] = b, etc. 现在标签[1] = b,依此类推。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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