Skip to content
On this page

Charts > Histogram ​

A histogram is a graphical representation of the distribution of numerical data, where bars of varying heights depict the frequency of values within specified ranges.

The Chart ​

undefined (NaN%)

Download example CSV
Copy HTML

Playground ​

Data

Number of bins (approximation)

Style

Color for bars

Component API ​

This chart is built using SVG and d3. The d3 bin function is used to group data points in buckets of equal width. Use the thresholds prop to change the number of bins (not guaranteed, only an approximation).

Usage Example (with tooltip) ​

vue
<template>
  <Histogram
    :key="key"
    :data="data"
    :color="color"
    :thresholds="20"
    @hover="setTooltip"
  />

  <OTTooltip :info="tooltip">
    <p class="font-semibold my-0">
      {{
        `${tooltip.data.length} (${(tooltip.data.length * data.length) / 100}%)`
      }}
    </p>
  </OTTooltip>
</template>

<script setup>
import useTooltip from "@/functions/useTooltip.js";

const [tooltip, setTooltip] = useTooltip();
</script>

Data ​

js
[
        { id: "data1", name: "Data 1", value: 1 },
        { id: "data2", name: "Data 2", value: 1 },
        { id: "data3", name: "Data 3", value: 1 },
        { id: "data4", name: "Data 4", value: 3 },
...
      ]

Props ​

NameDefaultTypeDescription
data[]ArrayThe list of values
margin{ top: 0, right: 0, bottom: 18, left: 25 }ObjectThe space around the chart
color#e5e7ebStringThe color for bins
colorScalenullFunctionThe color scale for bins instead of uniform color
selectednullArrayThe selected range as [min, max] (e.g. with slider)
unselectedClassopacity-50StringThe class to style unselected bins
thresholdsnullNumberThe approximate number of bins
showComparefalseBooleanWhether to show compare marks
xFormatnullFunctionThe formatter for x axis labels
yFormatnullFunctionThe formatter for y axis labels
highlightednullNumber | StringThe id of the bar to highlight

Dependencies ​

  • d3