我有一个使用ng2- chart.js模块的图表。该图表显示y轴上的百分比和x轴上的时间。是否可以将y轴设置为显示0到100而不是基于数据的动态范围?
发布于 2018-10-10 04:06:48
尝试将以下内容添加到图表选项中:
scales : {
yAxes: [{
ticks: {
steps : 10,
stepValue : 10,
max : 100,
min: 0
}
}]
}发布于 2019-02-24 14:52:26
在我的name.component.html中:
<div style="display: block">
<canvas baseChart height="100" [datasets]="lineChartData" [labels]="lineChartLabels" [options]="lineChartOptions"
[colors]="lineChartColors" [legend]="lineChartLegend" [chartType]="lineChartType"></canvas>
在我的name.component.ts中:
public lineChartOptions: any = {
scales : {
yAxes: [{
ticks: {
beginAtZero: true,
stepValue: 10,
steps: 20,
max : 50,
}
}]
}
};发布于 2019-12-18 21:10:38
是的,您可以通过在y轴上使用tickOption来执行相同的操作
public barChartOptions: ChartOptions = {
responsive: true,
showLines: false,
tooltips: {enabled: false},
animation: {duration: 2000},
scales: {
yAxes: [{
gridLines: {
display:false
},
display: false,
ticks: {
max : 100,
min: 0
}
}]
}
};此外,steps和stepValue不工作,我在他们的库中检查了同样的东西,它也没有写在那里。
barChartData: ChartDataSets[] = [
{
data: [40, 30, 30],
"backgroundColor": this.bgColors
}
];在上面,我只需要y条形图,所以我设置了这样的数据,对于这三个值,我使用了相同大小的barChartLabels。
barChartLabels: Label[] = ['A', 'B', 'C'];这对我很有效,我希望它也能在你的代码中起作用:)
https://stackoverflow.com/questions/51951109
复制相似问题