我正在使用ng 2-charts开发Angular应用程序。我试图在一个条形图中显示两个系列数据。我能够成功地做到这一点,但我的条形图彼此粘连。我希望两个条形图之间有空间。
x1c 0d1x的数据
如果我从数据中删除酒吧的厚度,它会自动占用酒吧之间的空间,但酒吧是如此之厚,这不是按照我的设计。我试图实现像https://appstack.bootlab.io/charts-chartjs.html这个网站的东西。
下面是我的代码。
chart.html
<div style="display: block;">
<canvas baseChart
[datasets]="barChartData"
[colors] = "barChartColors"
[labels]="barChartLabels"
[options]="barChartOptions"
[plugins]="barChartPlugins"
[legend]="barChartLegend"
[chartType]="barChartType">
</canvas>
</div>
字符串
Chart.ts
public barChartOptions: ChartOptions = {
scales: {
xAxes: [
{
gridLines: {
display: false
}
}
],
yAxes: [
{
gridLines: {
display: false
},
ticks: {
beginAtZero: true
}
}
]
},
responsive: true,
cornerRadius: 100,
plugins: {
labels: {
render: 'value'
}
},
legend: {
position: 'bottom',
labels: {
fontColor: 'black',
boxWidth: 20,
padding: 20,
fontFamily: 'Poppins',
fontSize: 13
}
},
animation: {
animateScale: true,
animateRotate: true
}
};
public barChartLabels: Label[] = ['2006', '2007', '2008', '2009', '2010', '2011', '2012'];
public barChartType: ChartType = 'bar';
public barChartLegend = true;
public barChartPlugins = [];
public barChartColors = [{
backgroundColor: '#3f80ea',
borderColor: '#3f80ea',
pointBackgroundColor: 'rgba(148,159,177,1)',
pointBorderColor: '#fff',
pointHoverBackgroundColor: '#fff',
pointHoverBorderColor: 'rgba(148,159,177,0.8)',
borderWidth: 3
}]
public barChartData: ChartDataSets[] = [
{ data: [65, 59, 80, 81, 56, 55, 40], label: 'Series A', barThickness :10 },
{ data: [28, 48, 40, 19, 86, 27, 90], label: 'Series B', barThickness :10}
];
型
任何帮助将高度赞赏,因为我正在努力我的水平最好作为初学者通过这一点
2条答案
按热度按时间thtygnil1#
如果我理解你的意思,你希望条形图的每一部分都加倍,也就是说给你两段数据
enter image description here
现在你只需要像这样写音阶部分
字符串
的数据
这真的不太可能,但我使用的是最新的Angular版本
wooyq4lh2#
如果你想要一个空格-你可以添加另一个数据集,像这样:
字符串