“” 1980“,” 2.4“
“” 1981“,” 2.6“
“ 1982”,“ 2.7”
此数据不:
“” 2016年5月“,” 6.9“
“” 2016年6月“,” 6.8“
“” 2016年7月“,” 7.0“
这是我的代码:
window.addEventListener('load', setup);
async function setup() {
var ctx = document.getElementById('myChart').getContext('2d');
var dollar = await getData();
var myChart = new Chart(ctx, {
type: 'line',
data: {
labels: dollar.years,
datasets: [
{label: 'Unemployment rate',
data: dollar.vals,
borderColor: 'rgb(153,222,101)',
backgroundColor: 'rgb(153,222,101, 0.2)',
pointRadius: 0,
borderWidth: 6,
pointHitRadius: 10,
}]
},
options: {
layout: {
padding: {
left: 0,
right: 15,
top: 0,
bottom: 0}
},
responsive: true,
title: {
display: false
},
legend: {
display: false
},
scales: {
yAxes: [{
ticks: {
min: 3,
max: 8,
stepSize: 1
}
}],
xAxes: [{
type: "time",
time: {
unit: "year",
tooltipFormat: "YYYY"
},
gridLines: {
display: true,
drawOnChartArea: false,
},
ticks: {
display: true,
maxTicksLimit: 5,
maxRotation: 0,
minRotation: 0,
padding: 1
},
}],
}
}
});
}
这是我在Chrome中遇到的错误。有什么想法吗?
弃用警告:提供的值不是公认的RFC2822或ISO格式。此刻的构建可以归结为js Date(),它在所有浏览器和版本之间都不可靠。不建议使用非RFC2822 / ISO日期格式,并将在即将发布的主要版本中将其删除。请参考http://momentjs.com/guides/#/warnings/js-date/了解更多信息。
我的两个图表未正确显示在野生动物园中。外观如下:它们在chrome中看起来很棒:我有一些图表是在chart.js中创建的,它们在chrome中可以正常工作,但是当我查看...
window.addEventListener('load', setup);
var formatDate = (dateString) => {
return moment(dateString, "MMM YYYY").toDate()
}
async function setup() {
var ctx = document.getElementById('myChart').getContext('2d');
var dollar = await getData();
var myChart = new Chart(ctx, {
type: 'line',
data: {
labels: dollar.years.map(year => formatDate(year)),
datasets: [{
label: 'Unemployment rate',
data: dollar.vals,
borderColor: 'rgb(153,222,101)',
backgroundColor: 'rgb(153,222,101, 0.2)',
pointRadius: 0,
borderWidth: 6,
pointHitRadius: 10,
}]
},
options: {
layout: {
padding: {
left: 0,
right: 15,
top: 0,
bottom: 0
}
},
responsive: true,
title: {
display: false
},
legend: {
display: false
},
scales: {
yAxes: [{
ticks: {
min: 3,
max: 8,
stepSize: 1
}
}],
xAxes: [{
type: "time",
time: {
unit: "year",
tooltipFormat: "YYYY"
},
gridLines: {
display: true,
drawOnChartArea: false,
},
ticks: {
display: true,
maxTicksLimit: 5,
maxRotation: 0,
minRotation: 0,
padding: 1
},
}],
}
}
});
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.24.0/moment.min.js"></script>