Skip to content
On this page

Ribbon Chart ​

A ribbon chart is a variation of a stacked bar chart that shows how data categories flow or change over time. It highlights shifts in rank or size between groups with colored ribbons connecting each segment.

The Chart ​

Other compatible charts

Download example CSV
Copy HTML

Playground ​

Data

Number of stacked layers

Style

Colors for ribbons
Use lines in the chart
Use curves in the chart

Animation

Duration of animation in ms

Usage Example (with tooltip) ​

vue
<template>
  <RibbonChart :data="data" @hover="setTooltip" />

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

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

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

Component API ​

The ribbon chart is built using SVG and d3. You can use it with different options like with or without curves or lines. The area shapes animate using d3 transition.

Data ​

js
[
  {
    id: "data-1",
    name: "Data 1",
    values: {
      val1: { id: "val1", name: "val 1", value: 60, order: 1 },
      val2: { id: "val2", name: "val 2", value: 40, order: 2 },
    },
  },
  {
    // ...
  },
];

Props ​

NameDefaultTypeDescription
dataArray of example dataArrayDataset for the ribbon chart
color{ val1: "#eee", val2: "#ccc" }ObjectColors for each segment
rectStyle{ val1: "rect", val2: "line" }ObjectStyle (e.g., shape) for each segment
margin{ top: 0, right: 0, bottom: 20, left: 0 }ObjectMargin around the chart
maxnullNumberFixed max value for y-axis
duration500NumberDuration of animations in milliseconds
ease"easeCubic"StringEasing function for animations
refLinenullNumberValue at which to show a reference line
refLineText""StringLabel for the reference line
showXAxistrueBooleanWhether to show the X axis
showYAxisfalseBooleanWhether to show the Y axis
yTickValuesnullArrayValues to show as Y axis ticks
xTickValuesnullArrayValues to show as X axis ticks
paddingInner0.6NumberPadding between bars
paddingOuter0NumberPadding on the sides of the chart
bgColornullStringBackground color for each column
format(d) => dFunctionFormatter function for Y axis values
stackedtrueBooleanWhether to stack the ribbons or not
keysnullArraySegment keys to use as layers, in order
useCurvestrueBooleanWhether to use curved shapes for ribbons
useLinesfalseBooleanWhether to use line-based layout for ribbons

Events ​

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

Dependencies ​

  • d3