【发布时间】:2019-07-01 15:18:17
【问题描述】:
实际上,我正在从 MySQL 解析一些数据,然后将它们序列化为 JSON。 下一步是我通过 AJAX 检索 JSON 并将数据放入 Chart.JS。
问题是日期值被格式化为
/日期(154564434687)/
这是 JQuery 代码,我在其中将值从解析的 JSON 设置为图表
function GetMOV() {
$.ajax({
type: "post",
url: "index.aspx/GetMOV",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (r) {
data = r.d;
data = jQuery.parseJSON(data)
new Chart(document.getElementById("linechart"), {
type: 'line',
data: {
labels: data.map(f => f.text),
datasets: [
{
label: "Venduto",
data: data.map(f => f.value),
fill: false,
borderColor: 'rgba(75,192,192,1)',
lineTension: 0.1,
borderWidth: 3,
pointBackgroundColor: '#fff',
pointBorderWidth: 1,
pointHoverRadius: 5,
borderCapStyle: 'square',
borderJoinStyle: 'square',
pointHitRadius: 20,
pointStyle: 'circle',
}
]
},
options: {
legend: { display: false },
scales: {
yAxes: [{
ticks: {
beginAtZero: true,
min: 0
},
time: {
unit: 'year'
}
}]
}
}
});
},
error: function (error) {
OnFailure(error);
alert('Error');
}
});
}
【问题讨论】:
-
您将日期值设置在图表的哪一行?
-
@SonalBorkar 标签:data.map(f => f.text) 此处
-
@Rob 我还尝试过类似 new Date(data.map(f=>f.text) 它不起作用,因为它不是字符串
标签: jquery asp.net json ajax chart.js