-1

Im using my angular project for ng2 chart, i have some conflict on the bar chart, can i know how to put value like this format 1000= 1k

here the stack blitz code

My code here

<div style="display: block;">
  <canvas baseChart 
    [datasets]="barChartData"
    [labels]="barChartLabels"
    [options]="barChartOptions"
    [plugins]="barChartPlugins"
    [legend]="barChartLegend"
    [chartType]="barChartType">
  </canvas>
</div>

.ts

 public barChartOptions: ChartOptions = {
    responsive: true,
  };
  public barChartLabels: Label[] = ['2006', '2007', '2008', '2009', '2010', '2011', '2012'];
  public barChartType: ChartType = 'bar';
  public barChartLegend = true;
  public barChartPlugins = [];

  public barChartData: ChartDataSets[] = [
    { data: [6500, 5900, 8000, 8100, 5600, 5500, 4000], label: 'Series A' },
    { data: [2800, 4800, 4000, 1900, 8600, 2700, 9000], label: 'Series B' }
  ];
core114
  • 5,155
  • 16
  • 92
  • 189

1 Answers1

1

The solution is simple, Read the full documentation of chartJS and ng2Charts. I have updated your code and you can find a Live Demo here. The solution is to add barChartOptions with ticks property.

public barChartOptions: ChartOptions = {
    responsive: true,
    scales: { //you're missing this
      yAxes: [{
         scaleLabel: {
            display: true,
            labelString: 'Frequency Rate'
         },
         ticks: { // and this
            callback: function(value, index, values) {
             return value/1000 + 'k';
          }
        }
      }]
   }
  };

Hope it helps!.. Happy Coding!!

Anglesvar
  • 1,132
  • 8
  • 15