在chart.js中,如何设置轴标签的字体大小?我尝试了很多代码,但都不起作用。我使用简单的条形图。I导入:
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
代码:
options: {
scales: {
x: {
display: true,
size: 30
}
}
}
在chart.js上,我读到名称空间是: options.scalesscaleId.title,但当我修改代码时,它也不起作用。https://www.chartjs.org/docs/3.3.2/axes/labelling.html
发布于 2021-08-02 19:25:30
您必须在标签的font
选项中配置它,如下所示:
var options = {
type: 'line',
data: {
labels: ["Red", "Blue", "Yellow", "Green", "Purple", "Orange"],
datasets: [{
label: '# of Votes',
data: [12, 19, 3, 5, 2, 3],
borderColor: 'pink'
}]
},
options: {
scales: {
x: {
ticks: {
font: {
size: 20
}
},
title: {
display: true,
text: 'titleX',
font: {
size: 25
}
}
},
y: {
ticks: {
font: {
size: 20
}
},
title: {
display: true,
text: 'titleY',
font: {
size: 20
}
}
}
}
}
}
var ctx = document.getElementById('chartJSContainer').getContext('2d');
new Chart(ctx, options);
<body>
<canvas id="chartJSContainer" width="600" height="400"></canvas>
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/3.5.0/chart.js"></script>
</body>
编辑:由于您想要使刻度更大,您仍然需要对字体对象执行此操作,但不是在刻度子类别中
https://stackoverflow.com/questions/68626564
复制相似问题