admin管理员组文章数量:1325236
Trying to get the Y axis scale labels to look like the image, to be position on top of the scale and not rotated.
scale options currently look like:
scales: {
yAxes: [{
id: 'temp',
scaleLabel: {
display: true,
labelString: '°C'
},
type: 'linear',
position: 'left'
}, {
id: 'ppm',
scaleLabel: {
display: true,
labelString: 'ppm',
},
type: 'linear',
position: 'left',
ticks: {
stepSize: 500
}
}, {
id: '%',
scaleLabel: {
display: true,
labelString: '%',
},
type: 'linear',
position: 'right',
ticks: {
max: 100,
min: 0
}
}]
}
/
Trying to get the Y axis scale labels to look like the image, to be position on top of the scale and not rotated.
scale options currently look like:
scales: {
yAxes: [{
id: 'temp',
scaleLabel: {
display: true,
labelString: '°C'
},
type: 'linear',
position: 'left'
}, {
id: 'ppm',
scaleLabel: {
display: true,
labelString: 'ppm',
},
type: 'linear',
position: 'left',
ticks: {
stepSize: 500
}
}, {
id: '%',
scaleLabel: {
display: true,
labelString: '%',
},
type: 'linear',
position: 'right',
ticks: {
max: 100,
min: 0
}
}]
}
https://jsfiddle/3a7qvtwz/2/
Share Improve this question asked Nov 15, 2017 at 16:19 Jack MasonJack Mason 631 gold badge2 silver badges7 bronze badges 2- scale label position can be changed as below,xAxes: [ { scaleLabel: { display: true, labelString: 'Frequency Hz' }, position: 'top' }] – Buminda Commented Dec 1, 2017 at 1:24
- @Buminda No this won't work. The 'position' in your answer is for entire y-axe. – quangteo.media Commented Sep 24, 2018 at 2:23
2 Answers
Reset to default 3You can use the Plugin Core API that offers a range of hooks that may be used for performing custom code. To draw the scale labels on top of the different yAxes
in your code sample, the afterDraw
hook could be defined as follows. It uses CanvasRenderingContext2D.fillText()
to draw text directly on the canvas
.
plugins:[{
afterDraw: chart => {
var ctx = chart.chart.ctx;
ctx.save();
ctx.font = "bold 14px Arial";
ctx.fillStyle = "gray";
var y = 50;
ctx.textAlign = 'left';
ctx.fillText('CO2', 5, y);
ctx.fillText('°C', 46, y);
ctx.textAlign = 'right';
ctx.fillText('%', chart.chart.width - 10, y);
ctx.restore();
}
}],
Please have a look at your amended JSFiddle
https://github./chartjs/Chart.js/issues/3706
It's still not supported,but there is a way to workaround.
title: { display: true, text: ['realTile','leftScalelabel...............................
many space....................................................... rightScalelabel'] },
本文标签: javascriptChartjs scaleLabel positionStack Overflow
版权声明:本文标题:javascript - Chartjs scaleLabel position - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742167422a2426086.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论