使用 chart.js 3.0.0 测试版
看来他们还没有实施任何方法来更改标签的字体属性(下面的自包含示例中的 Volume 和 Month )
我尝试了几种方法,但似乎这是不可能的
需要明确的是,我要更改颜色的是标签,而不是标题或数据集。
谁能证实这一点?
<html>
<head>
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/3.0.0-beta.12/chart.js"></script>
</head>
<body>
<div id="container" style='background-color:white' >
<canvas id="canvas"></canvas>
</div>
<script>
window.onload = function() {
var ctx = document.getElementById('canvas').getContext('2d');
var chart = new Chart(ctx, {
type: 'bar',
data: {
labels: ['January', 'February', 'March', 'April', 'May', 'June', 'July'],
datasets: [{
data: [ 50, -90, 75, 40, -100, 220, 11 ]
}]
},
options: {
indexAxis: 'y',
plugins: {
legend: {
display: false,
labels:{
fontSize: 20,
fontColor: 'red',
}
},
title: {
display: true,
text: 'Chart.js Horizontal Bar Chart'
},
},
scales: {
x: {
display: true,
scaleLabel: {
display: true,
labelString: 'Volume',
fontColor:'#666',
fontSize: 20,
fontStyle: 'italic'
}
},
y: {
display: true,
scaleLabel: {
display: true,
labelString: 'Month',
fontColor:'#666',
fontSize: 20,
fontStyle: 'bold'
}
}
}
}
});
};
</script>
</body>
</html>