Reputation: 11407
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>
Upvotes: 5
Views: 6688
Reputation: 21
public barChartOptions: ChartConfiguration['options'] = {
scales: {
x: { ticks: {
maxRotation: 70,
minRotation: 70,
}},
y: {
max: 20,
min: -20,
}
},
plugins: {
title: {
display: true,
text: 'Title Chart'
},
legend: {
display: true,
position: 'bottom',
},
datalabels: {
anchor: 'end',
align: 'end'
}
}
};
Upvotes: 2
Reputation: 4183
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
Upvotes: 11
Reputation: 123
It does not look like there's a title option in the canvas. Your best bet would likely be to bind another element in the template.
chart.component.html
<div>
<h3>{{ barChartTitle }}</h3>
<div style="display: block">
<canvas baseChart
[datasets]="barChartData"
[labels]="barChartLabels"
[options]="barChartOptions"
[legend]="barChartLegend"
[chartType]="barChartType"
(chartHover)="chartHovered($event)"
(chartClick)="chartClicked($event)"></canvas>
</div>
</div>
Upvotes: -1