我想要时间表刻度线,但标签未以时间格式显示。如何将标签更改为时间格式。就目前而言,int值中的标签值是[{3,5,6}]
var myChartLine = new Chart(ctx, {
type: 'line',
data: {
labels: theHour[0].times,
datasets: [{
label: 'Overall',
position: 'bottom',
backgroundColor: 'rgba(255, 99, 132)',
borderColor: 'rgb(255, 99, 132)',
borderWidth: 1,
fill: false,
data: theHour[0].overall,
datalabels: {
labels: {
即时通讯我想做的是,我尝试更改标签:
moment(theHour[0].times.toString(), "HH:mm")
但是它没有用。
将数字转换为日期并将其格式化为“ HH:mm”
var theHour = [3,5,6];
console.log(moment(new Date(0, 0, 0, theHour[0], 0, 0, 0)).format("HH:mm"));
console.log(moment(new Date(0, 0, 0, theHour[1], 0, 0, 0)).format("HH:mm"));
console.log(moment(new Date(0, 0, 0, theHour[2], 0, 0, 0)).format("HH:mm"));
<script src="https://momentjs.com/downloads/moment.js"></script>