Combo
A combo draws more than one mark on one x. Each series names its mark on encoding.y. A bar and a line in the same spec is the usual chart. The line can move to a second y axis when the units differ.
When to use it
Use a combo when two series share an x and should not share a mark. Revenue as bars and margin as a line is that chart. Orders as bars and fill rate as a line is the same idea. If every series is a bar, use a bar. If every series is a line, use a line.
Do not use a combo to stack several areas into one shape. That is a stacked area. Do not use a combo when the only difference is color. Same mark, several series, is still a bar or a line.
How series map to marks
encoding.y is a list. Each item is one series. mark on that item is bar, line, area, or range. The chart type stays combo. There is no encoding.bar.
Orders and fill rate, Revenue and margin, Jars this month, and Kilometres and pace each put mark: "bar" on the count and mark: "line" on the second series. The bar channels stay bars when you change the line.
{
"encoding": {
"y": [
{ "field": "revenue", "title": "Revenue", "mark": "bar" },
{ "field": "margin", "title": "Margin", "mark": "line", "axis": "y2" }
]
}
}Data
Each row is one x and one number per series. encoding.x is the category or the time. Wide data, one column per series, is the shape these examples use. Orders and fill rate is orders and rate across five weeks. Jars this month is jars and lids across ten weeks, on the same axis because both are counts.
Put the line on axis: "y2" when its units are not the bar's units. Name that axis with axes.y2. A rate or a percent belongs there. Kilometres and pace also reverses the right scale, so a faster week sits higher.
a11y.alt is required. One sentence, 10 to 500 characters, with the point of the chart.
A spec that renders
This is the smallest combo. version, type, and a11y.alt are required. Three months. Revenue is a bar. Margin is a line on the right axis, formatted as a percent. axes.y2 has to be set when a series uses that axis, or validate reports CK3002. Points show on hover. The legend sits on top when the key is omitted.
{
"version": "1",
"type": "combo",
"data": [
{
"month": "Jan",
"revenue": 100,
"margin": 0.2
},
{
"month": "Feb",
"revenue": 140,
"margin": 0.24
},
{
"month": "Mar",
"revenue": 130,
"margin": 0.22
}
],
"encoding": {
"x": "month",
"y": [
{
"field": "revenue",
"title": "Revenue",
"mark": "bar"
},
{
"field": "margin",
"title": "Margin",
"mark": "line",
"axis": "y2",
"format": "percent"
}
]
},
"axes": {
"y2": {
"title": "Margin",
"format": "percent"
}
},
"a11y": {
"alt": "Revenue and margin both finished the quarter higher than they started."
}
}Install core and the adapter for your framework. The menu in the sidebar picks the snippet. spec is the JSON above.
npm install @chartkitdev/core
npm install @chartkitdev/react
import { Chart } from "@chartkitdev/react";
export function Panel() {
return <Chart spec={spec} />;
}npm install @chartkitdev/core
npm install @chartkitdev/vanilla
import { mount } from "@chartkitdev/vanilla";
const chart = mount(document.querySelector("#chart"), spec);
chart.update(spec);npm install @chartkitdev/core
npm install @chartkitdev/vue
<script setup>
import { Chart } from "@chartkitdev/vue";
</script>
<template>
<Chart :spec="spec" />
</template>npm install @chartkitdev/core
npm install @chartkitdev/svelte
<script>
import { Chart } from "@chartkitdev/svelte";
</script>
<Chart {spec} />npm install @chartkitdev/core
npm install @chartkitdev/astro
---
import { Chart } from "@chartkitdev/astro";
---
<Chart spec={spec} />npm install @chartkitdev/core
npm install @chartkitdev/solid
import { Chart } from "@chartkitdev/solid";
export function Panel() {
return <Chart spec={spec} />;
}npm install @chartkitdev/core
npm install @chartkitdev/qwik
import { component$ } from "@builder.io/qwik";
import { Chart } from "@chartkitdev/qwik";
export const Panel = component$(() => {
return <Chart spec={spec} />;
});npm install @chartkitdev/core
npm install @chartkitdev/angular
import { Component } from "@angular/core";
import { Chart } from "@chartkitdev/angular";
@Component({
standalone: true,
imports: [Chart],
template: `<ck-chart [spec]="spec" />`,
})
export class Panel {
spec = spec;
}npm install @chartkitdev/core
npm install @chartkitdev/element
import "@chartkitdev/element";
const chart = document.querySelector("chart-kit");
chart.spec = spec;Each option below is a key on the spec. The demo changes that key and updates the chart and the snippet together.
Examples
The rail switches among existing combo specs. Orders and fill rate and Revenue and margin put the line on the right. Jars this month keeps both series on the left, and the tooltip is an index card. Kilometres and pace draws a point on every week.
Series mark
The Series mark control writes mark on every y channel that is not a bar. line draws the path. area fills under it. The bar channels are left alone, so the spec stays a mix.
{
"field": "margin",
"mark": "area",
"axis": "y2"
}range is a band from a low field to a high field. It needs lo and hi. Set that in the playground.
Line axis
The Line axis control sets axis on those same channels. Left deletes axis, which means y, the axis the bars use. Right writes axis: "y2". The other keys on the channel stay, including format, scale, and title.
Left also removes axes.y2 when no series still uses that axis. A y2 axis with no series is CK3002, and the chart stays blank. Right puts axes.y2 back: the example's axis when it had one, otherwise true.
Use the right axis when the line's numbers are not in the bar's units. A percent line on the bar axis will look flat, because 0.2 is nothing next to 100.
Points
mark.points is the markers on the combo's lines. It is none, hover, or always. The default is hover. always draws a marker on every point. Kilometres and pace sets that, and also sets a diamond on the pace channel. The diamond stays when you change this control. none draws the line only.
{
"mark": { "points": "always" }
}Legend
A combo with two series shows a legend. Omit legend, or set true, and it sits on top. false hides it. legend.position is top, right, bottom, left, or inside. Jars this month and Kilometres and pace put it on the bottom.
{
"legend": { "position": "bottom" }
}Tooltip
tooltip is on for a combo when the key is omitted. Hovering a category shows each series. tooltip: false turns the card off. tooltip: true turns it on.
{
"tooltip": false
}{
"tooltip": true
}tooltip.fields chooses the rows, and tooltip.position places the card. Jars this month and Kilometres and pace set an index card. Change those in the playground. Turning the card off and on again puts that object back.
The rest of the spec
mark.curve is how the line joins its points. The default is monotone. mark.gap is the bar gap. axes.y2.title and axes.y2.format label the right axis. A per-channel scale can reverse that axis. Theme presets live on the playground, with the full option list.