is there need to define axisY anywhere else .I defined it in barChartoptions.Please check.
<canvas baseChart *ngIf=”showBarChart && !noRecord” class=”chart base-chart” [colors]=”barChartColors” [datasets]=”barChartData”
[labels]=”barChartLabels” [options]=”barChartOptions” [legend]=”barChartLegend” [chartType]=”barChartType”
(chartHover)=”chartHovered($event)”
(chartClick)=”chartClicked($event)”>
</canvas>
my canvas tag is not taking options
suffix and label formatter both are not working.
public barChartOptions: any
= {
scaleShowVerticalLines: false,
responsive: true,
axisY: {
labelFormatter: function (e) {
alert(“k”)
return e.value + “K”;
}
}
};
here alert is also not working.
here is my html code
<canvas baseChart *ngIf=”showBarChart && !noRecord” class=”chart base-chart” [colors]=”barChartColors” [datasets]=”barChartData”
[labels]=”barChartLabels” [options]=”barChartOptions” [legend]=”barChartLegend” [chartType]=”barChartType” (chartHover)=”chartHovered($event)” (chartClick)=”chartClicked($event)”></canvas>
Js code
this.barChartOptions={
axisY: {
labelFormatter: {suffix: “K”}
},
};
i try to add suffix like this but it is not working. Plz help .
i want to add suffix K to yaxis label.
my js file
public getSalesAndPurchase() {
this._companiesService.getSalesAndPurchase(<any>localStorage.getItem(“org_id”), this.fromDate, this.endDate).subscribe(
data => {
this.data = <ResponseModel>data
if (this.data.success) {
this.salesAndPurchases = this.data.payload;
if(this.salesAndPurchases.stats!==undefined){
this.noRecord=false;
let income = [];
let expense = [];
this.salesAndPurchases = this.data.payload;
this.barChartData = [];
this.barChartLabels = [];
this.barChartColors=[
{
backgroundColor:’rgb(123, 190, 234)’,
},
{
backgroundColor:’#DE7D12′,
}
]
// axisY: {
// labelFormatter: addSymbols
// },
this.totalExpense = 0;
this.totalIncome = 0;
this.salesAndPurchases.stats.forEach(stat => {
this.totalIncome += stat.income == “” || stat.income == null ? 0 : parseFloat(stat.income);
this.totalExpense += stat.expense == “” || stat.expense == null ? 0 : parseFloat(stat.expense);
income.push(stat.income);
expense.push(stat.expense);
this.barChartLabels.push(stat.month);
});
this.barChartData.push({ data: income, label: ‘Income’ }, { data: expense, label: ‘Expense’ })
}
else{
this.noRecord=true;
}
} else {
this._toastService.presentToast(this.data.payload.message);
}
this.showBarChart = true;
}, error=>{
this.errorMessage = <any>error;
this._toastService.callError(this.errorMessage);
})
}
html file
<canvas baseChart *ngIf=”showBarChart && !noRecord” class=”chart base-chart” [colors]=”barChartColors” [datasets]=”barChartData” [labels]=”barChartLabels” [options]=”barChartOptions” [legend]=”barChartLegend” [chartType]=”barChartType” (chartHover)=”chartHovered($event)” (chartClick)=”chartClicked($event)”></canvas>
HOw i use label formatter in this ?? please help