我期待增加的數字旁邊的工具提示鼠標懸停在圖表當你得到一個百分比。我怎樣才能做到這一點?例如,我想在83.33
旁添加一個%
符號。
ERROR:
ERROR TypeError: Cannot read property '0' of undefined
at i.label (eval at <anonymous> (http://localhost:3000/js/app/bundle.js:1564:1), <anonymous>:37:63)
CODE:
// Pie
public pieChartLabels:string[] = [];
public pieChartData:number[] = [];
public pieChartType:string = 'pie';
public pieChartOptions:any = {};
ngOnInit() {
var result1 = parseFloat(((this.poll.counter1/(this.poll.counter2+this.poll.counter1))*100).toFixed(2));
var result2 = parseFloat(((this.poll.counter2/(this.poll.counter2+this.poll.counter1))*100).toFixed(2));
this.pieChartData = [result1, result2];
this.pieChartLabels = [this.poll.choice1, this.poll.choice2];
this.pieChartType = 'pie';
this.pieChartOptions = {
tooltips: {
callbacks: {
label: function (tooltipItems, data) {
return data.datasets[tooltipItems.datasetIndex].label + ': ' +
tooltipItems.pieChartLabels[tooltipItems.datasetIndex].replace(/(\d)(?=(\d{3})+\.)/g, '$1,');
}
}
}
}
// events
public chartClicked(e:any):void {
}
public chartHovered(e:any):void {
}
@jonrsharpe無論如何,你爲什麼要考慮的問題是過於寬泛?它非常具體:「我如何在Chart.js的工具提示中添加百分比符號?」 – Coder1000
爲什麼downvote?請解釋。如果有必要,我願意編輯我的問題。 – Coder1000