ng2 图表条形图需要系列 Angular 中 2 个条形之间的间距
我正在使用 ng2-charts 开发 Angular 应用程序。我试图在一个条形图中显示两个系列数据。我能够成功地做到这一点,但我的酒吧将两个彼此粘在一起。我想要两个酒吧之间有空间。
如果我从数据中删除条形厚度,它会自动占用条形之间的空间 b,但条形太厚,不符合我的设计。 我试图实现类似 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}
];
任何帮助将不胜感激,因为我正在尽力以初学者的水平来完成这个任务
I am working on Angular app with ng2-charts. I am trying to show two series data in one bar chart graph. I am able to do it successfully but my bars are sticking two each other. I want space between my two bars.
If I remove the bar thickness from data it automatically takes the space bbetween bars but then bar are so thick which are not as per my design.
I am trying to acheive something like https://appstack.bootlab.io/charts-chartjs.html this website.
Below is my code.
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}
];
Any help will be highly appreciated as I am trying my level best as beginner to get through this
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果我明白你的意思,你希望条形图的每个部分都加倍
这意味着向您显示两条数据
现在您只需要像这样编写比例部分
确实不太可能,但我正在使用最新的 Angular 版本
If I understand what you mean, you want each part of the bar chart to be doubled
That means show you two pieces of data
Now you just need to write the scales section like this
It really is not very likely, but I am using the latest Angular version
如果您想要之间有一个空格 - 您可以添加另一个数据集,如下所示:
If you want a space between - you can add another dataset, something like this: