Skip to content

Cumulative ​

A cumulative histogram shows running totals. With stat: 'percent', it answers questions such as "what share of requests finish within 200 ms?". Tooltips show ≤ 200 or ≥ 200 instead of a range.

Forward ​

ts
// A cumulative distribution: the share of requests at or under each time.
import type {ChartConfiguration} from 'chart.js';
import {responseTimes} from './data/index.js';

const config: ChartConfiguration<'histogram'> = {
  type: 'histogram',
  data: {
    datasets: [
      {
        label: 'Requests at or under',
        data: responseTimes,
        binWidth: 25,
        binStart: 0,
        domain: [0, 600],
        stat: 'percent',
        // Each bar is the share of values up to its upper edge.
        cumulative: 'forward'
      }
    ]
  },
  options: {
    scales: {
      x: {title: {display: true, text: 'Response time (ms)'}},
      y: {title: {display: true, text: 'Requests (%)'}}
    }
  }
};

export default config;

Reverse ​

ts
// Reverse cumulative: the share of requests at or over each time.
import type {ChartConfiguration} from 'chart.js';
import {responseTimes} from './data/index.js';

const config: ChartConfiguration<'histogram'> = {
  type: 'histogram',
  data: {
    datasets: [
      {
        label: 'Requests at or over',
        data: responseTimes,
        binWidth: 25,
        binStart: 0,
        domain: [0, 600],
        stat: 'percent',
        // Each bar is the share of values from its lower edge up.
        cumulative: 'reverse',
        backgroundColor: 'rgba(255, 99, 132, 0.7)'
      }
    ]
  },
  options: {
    scales: {
      x: {title: {display: true, text: 'Response time (ms)'}},
      y: {title: {display: true, text: 'Requests (%)'}}
    }
  }
};

export default config;

Released under the MIT License.