我只是在学习chart.js的工作方式,因此我直接在chart.js API页面之外使用了示例代码,但似乎不起作用。我将以下代码放在脚本标签中,并且收到“无法读取未定义的属性'generateLabels'”错误。不确定这个错误是什么意思
$(document).ready (function () {
$('.btn-primary').on('click', function (e) {
e.preventDefault();
var id = $(this).data('id')
$.ajax({
type: "POST",
url: "/HoaDon/ThongKeLuongDienSuDung",
data: { idKhachHang: id },
dataType: "json",
success: function (mems) {
var userData = mems;
var aData = JSON.parse(JSON.stringify(userData));
var aLabels = aData[0];
var aDatasets1 = aData[1];
//var iddiv = "Chart+" + id;
var ctx = $("#myChart-PH12348888")[0].getContext('2d');
var dataT = {
labels: aLabels,
datasets: [{
label: "d",
data: aDatasets1,
fill: false,
backgroundColor: ["rgba(54, 162, 235, 0.2)", "rgba(54, 162, 235, 0.2)", "rgba(54, 162, 235, 0.2)", "rgba(54, 162, 235, 0.2)", "rgba(54, 162, 235, 0.2)", "rgba(54, 162, 235, 0.2)", "rgba(54, 162, 235, 0.2)"],
borderColor: ["rgb(54, 162, 235)", "rgb(54, 162, 235)", "rgb(54, 162, 235)", "rgb(54, 162, 235)", "rgb(54, 162, 235)", "rgb(54, 162, 235)", "rgb(54, 162, 2357)"],
borderWidth: 1
}]
};
var myNewChart = new Chart(ctx, {
type: 'bar',
data: dataT,
options: {
responsive: true,
title: { display: true, text: 'CHART.JS DEMO CHART' },
legend: { position: 'bottom' },
scales: {
xAxes: [{ gridLines: { display: false }, display: true, scaleLabel: { display: false, labelString: '' } }],
yAxes: [{ gridLines: { display: false }, display: true, scaleLabel: { display: false, labelString: '' }, ticks: { stepSize: 50, beginAtZero: true } }]
},
}
});
}
});
});
})