I'm using the ng2-charts wrapper for ChartJS in Angular, and attempting to place an image along with the text in my x-axis ticks like this:
My component looks like this, just using static data at this point to prove the concept:
import { Component, ViewChild } from '@angular/core';
import {
Chart,
ChartConfiguration,
ChartData,
ChartType,
} from 'chart.js';
import { BaseChartDirective } from 'ng2-charts';
import { default as Annotation } from 'chartjs-plugin-annotation';
@Component({
selector: 'app-bar-chart',
templateUrl: './bar-chart.component.html',
styleUrls: ['./bar-chart.component.scss'],
})
export class BarChartComponent {
@ViewChild(BaseChartDirective) chart: BaseChartDirective | undefined;
constructor() {
Chart.register(Annotation);
}
public barChartOptions: ChartConfiguration['options'] = {
responsive: true,
scales: {
x: {
type: 'category'
},
y: {
type: 'linear',
min: 50,
max: 100,
title: {
display: true,
text: 'Compliance Rate / Range'
},
ticks: {
callback: function (value, index, values) {
return value + '%';
},
},
},
},
plugins: {
legend: {
display: false,
},
annotation: {
annotations: {
line1: {
type: 'line',
yMin: 80,
yMax: 80,
borderColor: '#000000',
borderDash: [2, 2],
borderWidth: 2,
},
},
},
},
};
public barChartType: ChartType = 'bar';
public barChartData: ChartData<any> = {
labels: [
['Audit 1', '2016'],
['Audit 2', '2016'],
['Audit 3', '2016'],
['Audit 1', '2017'],
['Audit 2', '2017'],
['Audit 3', '2017'],
],
datasets: [
{
data: [80, 85, 70, 73, 70, 82],
label: 'Series B',
type: 'line',
borderColor: '#1464a4',
backgroundColor: '#FFFFFF',
pointBackgroundColor: '#FFFFFF',
pointBorderColor: '#1464a4',
pointRadius: 6,
pointBorderWidth: 3,
},
{
data: [
[62, 95],
[75, 87],
[63, 79],
[61, 98],
[63, 75],
[60, 90],
],
label: 'Hand Hygiene Compliance Range',
type: 'bar',
barPercentage: 0.3,
backgroundColor: [
'#93c845',
'#93c845',
'#b41744',
'#93c845',
'#b41744',
'#93c845',
],
},
],
};
}
The only thing missing is the icons under the tick label text on the x-axis.
Can anyone help with whether it's possible and if so, how?