Appearance
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)
| Name | val1 | val2 | val3 |
|---|---|---|---|
| Septiembre | 12 | 5 | 21 |
| Octubre | 7 | 13 | 12 |
| Noviembre | 34 | 3 | 16 |
| Diciembre | 20 | 12 | 24 |
INFO
Optional: color on value object
Props
| Name | Type | Default | Description |
|---|---|---|---|
data | Array | [] | The dataset |
keys | Array | null | The ids of segments to create layers for, in order |
max | Number | null | The max value of the y axis |
margin | Object | { top: 0, right: 0, ... } | The margins to use on each side in px |
refLine | Number | null | The position for a reference line (e.g. avg or median) |
refLineText | String | '' | The label for the reference line |
color | Object | { val1: '#eee', val2: '#ccc' } | The default color for each segment |
bgColor | String | null | The color for background of columns |
duration | Number | 300 | The time of the animation in ms |
ease | String | easeCubic | The easing function for animation |
format | Function | (d) => d | The format function for y axis labels |
showXAxis | Boolean | true | Whether or not to show the x axis |
showYAxis | Boolean | false | Whether or not to show the y axis |
yTickValues | Array | null | The values to show on the y axis |
xTickValues | Array | null | The values to show on the x axis |
paddingInner | Number | 0.1 | The space between columns |
paddingOuter | Number | 0.1 | The space on the sides of the chart |
Events
| Event | Argument | Description |
|---|---|---|
@select | { target, data } | Emitted when bar is clicked |
Dependendencies
- d3