Skip to content
On this page

Charts > Column chart ​

A stacked column chart visually displays multiple data series in vertical columns, using segmented sections to represent cumulative values for each category.

The Chart ​

Beer
Spirit
Wine

Beer:

Spirit:

Wine:

Servings of beer, spirits and wine per person in different European countries, 2010. Source: FiveThirtyEight

Download example CSV
Copy HTML

Playground ​

Data
Use percentage values
Number of bars
Number of values
Show reference line
Label for reference line
Animation
Duration of animation in ms
Easing curve (D3)
Style
Colors for areas
Color for background of bar
Show y axis
Show bars stacked
Section styles for unstacked chart
Padding between bars
Padding on the sides

Component API ​

The column chart is built using SVG and can be used as a regular column chart or a stacked column chart with multiple segments per column. Use the keys prop to control which segments are drawn as layers and in which order. If not given, the keys are taken from the first data element's values object.

Usage Example (with tooltip) ​

vue
<template>
  <ColumnChart
    :data="data"
    @hover="setTooltip"
    class="h-72 mt-8"
    style="width: 100%; height: 200px;"
  />

  <OTTooltip :info="tooltip">
    <p v-for="item in Object.keys(tooltip.data.values)" class="my-0">
      <span class="font-medium">{{ item }}: </span>
      {{ tooltip.data.values[item].value }}
    </p>
  </OTTooltip>
</template>

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

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

Data ​

js
[
  {
    id: "data-1",
    name: "Data 1",
    values: {
      val1: { id: "val1", name: "val 1", value: 60 },
      val2: { id: "val2", name: "val 2", value: 40 },
    },
  },
  {
    // ...
  },
];
Data Shape for Uploadable CSV (example data)
Nameval1val2val3
Septiembre12521
Octubre71312
Noviembre34316
Diciembre201224

INFO

Optional: color on value object

Props ​

NameTypeDefaultDescription
dataArray[]The dataset
keysArraynullThe ids of segments to create layers for, in order
maxNumbernullThe max value of the y axis
marginObject{ top: 0, right: 0, ... }The margins to use on each side in px
refLineNumbernullThe position for a reference line (e.g. avg or median)
refLineTextString''The label for the reference line
colorObject{ val1: '#eee', val2: '#ccc' }The default color for each segment
bgColorStringnullThe color for background of columns
durationNumber300The time of the animation in ms
easeStringeaseCubicThe easing function for animation
formatFunction(d) => dThe format function for y axis labels
showXAxisBooleantrueWhether or not to show the x axis
showYAxisBooleanfalseWhether or not to show the y axis
yTickValuesArraynullThe values to show on the y axis
xTickValuesArraynullThe values to show on the x axis
paddingInnerNumber0.1The space between columns
paddingOuterNumber0.1The space on the sides of the chart

Events ​

EventArgumentDescription
@select{ target, data }Emitted when bar is clicked

Dependendencies ​

  • d3