angular - 角度图表js条形图宽度不起作用
问题描述
我正在为我的项目使用 angular 12 和 chart js 最新版本我正在尝试将条形图宽度做得很小但 barPercentage: 0.4
无法在我的代码中添加任何解决方案?
这里的代码
var myChart = new Chart('myChart', {
type: 'bar',
data: {
labels: this.labels,
datasets: [
{
data: this.data,
backgroundColor: [' rgba(148, 180, 214,0.4)', 'rgba(239, 83, 80,0.4)', 'rgba(102, 187, 106,0.4)'],
borderColor: [' #93b3d6', '#ef5350', '#66bb6a'],borderWidth: 1
},
],
},
options: {
plugins: {
legend: {
display: false,
},
},
responsive: true,
maintainAspectRatio: true,
datasets: {
bar: {
categoryPercentage: 0.95
}
},
scales: {
y: {
title: {
display: true,
text: 'Count',
},
},
x: {
title: {
display: false,
text: 'Total Count',
},
},
},
},
});
谢谢
解决方案
您应该添加barPercentage
每个dataset
.
datasets: [
{
data: this.data,
backgroundColor: [' rgba(148, 180, 214,0.4)', 'rgba(239, 83, 80,0.4)', 'rgba(102, 187, 106,0.4)'],
borderColor: [' #93b3d6', '#ef5350', '#66bb6a'],
borderWidth: 1,
barPercentage: 0.4
},
],
```
推荐阅读
- react-native - 无法使用 useState 更改函数组件上的数组数据
- python - 为什么 python 在我的 Mac 上突然变慢了?
- android - Google 分析跟踪 ID 未显示
- c++ - 如何修复'd:未找到架构 x86_64 clang 的符号:错误:链接器命令失败,退出代码为 1(使用 -v 查看调用)'?
- microsoft-cognitive - 如何在 MS Flow 或 Logic Apps 中获得配色方案?
- c# - 已删除计划的 Toast 通知
- sql-server - 在 SQL Server 中为不同的 XML 大小在表中存储 XML 标记
- javascript - 当我单击按钮时,react-native-image-crop-picker 出现错误“null 不是对象”
- javascript - 我的命令在我运行它时没有设置我的角色 ID,它从来没有设置它?
- android - JSONArray 无法转换为 JSONObject