Skip to content

Horizontal ​

Set indexAxis: 'y' to lay the bins along the y axis.

ts
// Horizontal bars: set indexAxis to 'y'.
import type {ChartConfiguration} from 'chart.js';
import {responseTimes} from './data/index.js';

const config: ChartConfiguration<'histogram'> = {
  type: 'histogram',
  data: {
    datasets: [{label: 'Requests', data: responseTimes, bins: 'fd', domain: [0, 700]}]
  },
  options: {
    // The bins run along the y axis.
    indexAxis: 'y',
    scales: {
      x: {title: {display: true, text: 'Requests'}},
      y: {reverse: true, title: {display: true, text: 'Response time (ms)'}}
    }
  }
};

export default config;

Released under the MIT License.