gpt4 book ai didi

javascript - 未捕获的类型错误 : Cannot create property '_meta' on string

转载 作者:塔克拉玛干 更新时间:2023-11-02 21:58:41 49 4
gpt4 key购买 nike

我已经能够使用 Chartjs 中的静态数据绘制条形图、折线图。但是当我尝试通过一些 api 使用动态接收的数据时,会显示一些错误消息。我的代码是:

//'myCanvas' is the id for the canvas, where chart has to be drawn
const CHART = document.getElementById('myCanvas').getContext('2d');
var userData = {};
var dateArray = [];
var dataArray = [];

var barChartData = {
labels: dateArray,
datasets: {
label: "users",
fillColor: '#382765',
data: dataArray
}
};

var configure = {
type: 'bar',
data: barChartData
//I have removed the option part from here to make this post compact
};

window.barChart = new Chart(CHART, configure);
window.barChart.render();
//fillData is called from HTML form submission
function fillData() {
$.ajax({
type: 'GET',
url: '/api/v1/data',
data: 'start=' + document.getElementById('start').value + '&end=' + document.getElementById('end').value,
success: function dataGet(data) {
userData = JSON.parse(data);
dataParse();
}
});
window.barChart.update();
}

function dataParse() {
for(var i = 0; i < userData.length; i++){
dateArray.push(new Date(userData[i].date));
dataArray.push(userData[i].users);
}
}

我得到的错误是这样的:

Uncaught TypeError: Cannot create property '_meta' on string 'users'
getDatasetMeta @ Chart.min.js:12
(anonymous function) @ Chart.min.js:12
o.each @ Chart.min.js:12
buildOrUpdateControllers @ Chart.min.js:12
initialize @ Chart.min.js:12
t.Controller @ Chart.min.js:12
t @ Chart.min.js:13
(anonymous function) @ main.js:48

Uncaught TypeError: Cannot create property '_meta' on string 'users'
getDatasetMeta @ Chart.min.js:12
isDatasetVisible @ Chart.min.js:12
(anonymous function) @ Chart.min.js:12
o.each @ Chart.min.js:12
getElementAtEvent @ Chart.min.js:12
a @ Chart.min.js:12eventHandler @ Chart.min.js:12
(anonymous function) @ Chart.min.js:12
t.events.(anonymous function) @ Chart.min.js:12

Uncaught TypeError: Cannot read property 'initialize' of undefined

最佳答案

您传递的数据与 docs 不一致|

你能试试把 datasets 做成数组吗?

此外,尝试在最初提供静态数据以允许图表使用一些模拟数据进行初始化。

关于javascript - 未捕获的类型错误 : Cannot create property '_meta' on string,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38414331/

49 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com