[Chartjs]-Display Time In Y Axis – Bubble Chart

2👍

You can use a custom label formatter to display time values instead of numbers.

times = [
  "3:00 am",
  "7:00 am",
  "11:00 am",
  "3:00 pm",
  "7:00 pm",
  "11:00 pm",
]

public bubbleChartOptions: ChartOptions = {
  responsive: true,
  scales: {
    xAxes: [{ ticks: { min: 0, max: 30, } }],
    yAxes: [{
      ticks: {
        min: 0, max: 5,
        callback: value => this.times[value]
      }
    }]
  }
};

public bubbleChartData: ChartDataSets[] = [
  {
    data: [
      { x: 7, y: 0, r: 8 },
      { x: 10, y: 1, r: 10 },
      { x: 15, y: 2, r: 15 },
      { x: 26, y: 3, r: 23 },
    ],
    label: 'Series A',
  },
];

See this stackblitz for example.

Here’s the image output:

enter image description here

Leave a comment