将 Chart.js 折线图上的 scaleLabel(无刻度或标签)顺时针旋转 90 度
Rotate 90 degrees clockwise the scaleLabel (no ticks or labels) on a Chart.js line chart
如何在yAxis上顺时针旋转90度显示scaleLabel?不是刻度或标签,而是通常位于 y 轴左侧的单个元素。在此示例中,包含字符串:labelString:'My Label'
var options = {
type: 'line',
data: {
labels: ["Red", "Blue", "Yellow", "Green", "Purple", "Orange"],
datasets: [
{
label: '# of Votes',
data: [12, 19, 3, 5, 2, 3],
borderWidth: 1
},
{
label: '# of Points',
data: [7, 11, 5, 8, 3, 7],
borderWidth: 1
}
]
},
options: {
scales: {
yAxes: [{
scaleLabel:{
display:true,
labelString:'My Label'
},
ticks: {
reverse: false
}
}]
}
}
}
var ctx = document.getElementById('chartJSContainer').getContext('2d');
new Chart(ctx, options);
我的 jsfiddle:https://jsfiddle.net/aq57fxjp/
您可以通过注释掉
行来获得所需的效果
rotation = isLeft ? -0.5 * Math.PI : 0.5 * Math.PI;
在源代码中。
如何在yAxis上顺时针旋转90度显示scaleLabel?不是刻度或标签,而是通常位于 y 轴左侧的单个元素。在此示例中,包含字符串:labelString:'My Label'
var options = {
type: 'line',
data: {
labels: ["Red", "Blue", "Yellow", "Green", "Purple", "Orange"],
datasets: [
{
label: '# of Votes',
data: [12, 19, 3, 5, 2, 3],
borderWidth: 1
},
{
label: '# of Points',
data: [7, 11, 5, 8, 3, 7],
borderWidth: 1
}
]
},
options: {
scales: {
yAxes: [{
scaleLabel:{
display:true,
labelString:'My Label'
},
ticks: {
reverse: false
}
}]
}
}
}
var ctx = document.getElementById('chartJSContainer').getContext('2d');
new Chart(ctx, options);
我的 jsfiddle:https://jsfiddle.net/aq57fxjp/
您可以通过注释掉
行来获得所需的效果rotation = isLeft ? -0.5 * Math.PI : 0.5 * Math.PI;
在源代码中。