gpt4 book ai didi

javascript - 如何更改 Chart.js 中标记比例的字体大小?

转载 作者:行者123 更新时间:2023-12-04 17:00:56 25 4
gpt4 key购买 nike

在chart.js中如何设置轴标签的字体大小?
我尝试了很多代码,但都没有奏效。我使用一个简单的条形图。
我进口:

<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
代码:
  options: {
scales: {
x: {
display: true,
size: 30
}
}
}
在我读过的 chart.js 上,命名空间是: options.scales[scaleId].title 但它也没有工作,当我修改我的代码时。
https://www.chartjs.org/docs/3.3.2/axes/labelling.html

最佳答案

您必须在 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>

编辑:
由于您想让刻度线更大,因此您仍然需要使用字体对象执行此操作,而不是在刻度子类别中

关于javascript - 如何更改 Chart.js 中标记比例的字体大小?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68626564/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com