Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to add a title to my ng2-charts bar chart

I have a bar chart with below code...works brilliantly....except its missing a title.

Does ng2-charts have a title option in API? eg 'sales chart'. The values are pulled from the typescript file.

<div>
  <div style="display: block">
    <canvas baseChart
            [datasets]="barChartData"
            [labels]="barChartLabels"
            [options]="barChartOptions"
            [legend]="barChartLegend"
            [chartType]="barChartType"
            (chartHover)="chartHovered($event)"
            (chartClick)="chartClicked($event)"></canvas>
  </div>

like image 238
Fearghal Avatar asked Feb 06 '23 04:02

Fearghal


1 Answers

You can specify it as part of the chart options, e.g.

  private barChartOptions = {
    title: {
      text: 'my title',
      display: true
    }
  };

You can specify additional properties for font size etc, see the docs at: http://www.chartjs.org/docs/latest/configuration/title.html

like image 99
Joseph Simpson Avatar answered Feb 07 '23 19:02

Joseph Simpson