Chart.js - 2 不显示 Axes 标签
Chart.js - 2 does not display Axes labels
我正在尝试使用 vue-chartjs 和 Chart.js (2.7.1) 绘制折线图。
图表已显示,但没有 xAxes 和 yAxes 标签。
这是我的选项对象:
title: {
display: true,
text: 'Title',
},
responsive: true,
maintainAspectRatio: false,
elements: {
line: {
fill: false
}
},
scales: {
xAxes: {
scaleLabel: {
display: true,
labelString: 'LabelX',
}
},
yAxes: {
scaleLabel: {
display: true,
labelString: 'LabelY',
}
},
}
我认为 scales.xAxes.scaleLabel 不起作用。
在 Chartjs 2.x.x 版本中,您必须在数组而不是对象中指定比例选项。
这样试试
xAxes: [{
scaleLabel: {
display: true,
labelString: 'LabelX',
},
gridLines: {
display: true
}
}]
您正在尝试将 V3 语法与 V2 结合使用,但这是行不通的。你必须这样说:
scales:{
xAxes: [
{
scaleLabel: {
display: true,
labelString: 'text'
}
}
],
yAxes: [
{
scaleLabel: {
display: true,
labelString: 'text'
}
}
]
}
我正在尝试使用 vue-chartjs 和 Chart.js (2.7.1) 绘制折线图。 图表已显示,但没有 xAxes 和 yAxes 标签。
这是我的选项对象:
title: {
display: true,
text: 'Title',
},
responsive: true,
maintainAspectRatio: false,
elements: {
line: {
fill: false
}
},
scales: {
xAxes: {
scaleLabel: {
display: true,
labelString: 'LabelX',
}
},
yAxes: {
scaleLabel: {
display: true,
labelString: 'LabelY',
}
},
}
我认为 scales.xAxes.scaleLabel 不起作用。
在 Chartjs 2.x.x 版本中,您必须在数组而不是对象中指定比例选项。
这样试试
xAxes: [{
scaleLabel: {
display: true,
labelString: 'LabelX',
},
gridLines: {
display: true
}
}]
您正在尝试将 V3 语法与 V2 结合使用,但这是行不通的。你必须这样说:
scales:{
xAxes: [
{
scaleLabel: {
display: true,
labelString: 'text'
}
}
],
yAxes: [
{
scaleLabel: {
display: true,
labelString: 'text'
}
}
]
}