Chart.js v3:如何增大图表图例的字体大小?
Chart.js v3: How can I grow fontsize of legend of my graph?
我将 Chart.js
HTML 页面从 2.7 版迁移到 3.4 版,只剩下一个问题。
无法更改图例的字体大小。
我尝试了以下代码
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/3.4.0/chart.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/chartjs-plugin-annotation/1.0.2/chartjs-plugin-annotation.min.js"></script>
legend:
{ font: { size: 80 }
, title:
{ display: true
, font: { size: 80 }
, color: 'Green'
}
,labels:
{ font: { size: 80 }
, color: 'Green'
}
},
但字体大小没有改变!
怎样才能让图例字体变大?
在下图中,您可以看到我的图表的图例(k=1、k=2、...、k=8)。
我假设您在错误的地方选择了图例:
如迁移指南中所述,图例、插件工具提示和标题已移至插件部分。
示例:
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: {
plugins: {
legend: {
labels: {
font: {
size: 30
}
}
}
}
}
}
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.4.0/chart.js"></script>
</body>
我将 Chart.js
HTML 页面从 2.7 版迁移到 3.4 版,只剩下一个问题。
无法更改图例的字体大小。
我尝试了以下代码
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/3.4.0/chart.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/chartjs-plugin-annotation/1.0.2/chartjs-plugin-annotation.min.js"></script>
legend:
{ font: { size: 80 }
, title:
{ display: true
, font: { size: 80 }
, color: 'Green'
}
,labels:
{ font: { size: 80 }
, color: 'Green'
}
},
但字体大小没有改变!
怎样才能让图例字体变大?
在下图中,您可以看到我的图表的图例(k=1、k=2、...、k=8)。
我假设您在错误的地方选择了图例:
如迁移指南中所述,图例、插件工具提示和标题已移至插件部分。
示例:
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: {
plugins: {
legend: {
labels: {
font: {
size: 30
}
}
}
}
}
}
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.4.0/chart.js"></script>
</body>