我使用ionViewDidLoad() {
console.log("milk total",this.chartValue);
this.barChart = new Chart(this.barCanvas.nativeElement, {
type: 'bar',
data: {
labels: ["Milk", "News Paper", "Laundry", "Fruit/Veg"],
datasets: [{
label: '# of Total Price',
data: this.chartValue,
backgroundColor: [
'rgba(255, 99, 132, 0.2)',
'rgba(54, 162, 235, 0.2)',
'rgba(255, 206, 86, 0.2)',
'rgba(75, 192, 192, 0.2)',
'rgba(153, 102, 255, 0.2)',
'rgba(255, 159, 64, 0.2)',
],
borderColor: [
'rgba(255,99,132,1)',
'rgba(54, 162, 235, 1)',
'rgba(255, 206, 86, 1)',
'rgba(75, 192, 192, 1)',
'rgba(153, 102, 255, 1)',
'rgba(255, 159, 64, 1)'
],
borderWidth: 1
}]
},
options: {
scales: {
yAxes: [{
ticks: {
beginAtZero: true
}
}]
}
}
});
}
在我的应用中显示图表,并在ts文件中使用以下内容
{{1}}
我能够获得数组值,如" 22"," 0"," 18" .....只有点击红色我的条形图上方的颜色标签。我需要图表在页面加载后显示其值,并建议我如何删除该红色标签
答案 0 :(得分:0)
我没有发现您的代码有任何问题。它应该按原样运作。
也许尝试使用update()
方法在创建图表后强制更新图表,如下所示:
ionViewDidLoad() {
this.barChart = new Chart(this.barCanvas.nativeElement, {
...
...
});
this.barChart.update();
}