Spike

A spike draws a thin stem at each position, from a baseline up to the value. Quiet buckets sit on the baseline. A burst is a tall stem. The chart is for events over time, not for comparing thick bars.

When to use it

Use a spike when most values hug a baseline and a few jump: blocked requests, jolts, errors in a bucket. The stem makes the burst obvious. The quiet hours stay flat.

A bar gives each category a width and a scale you can read across. Bars can stack and group. A spike has no bar width and does not stack. It is a stem, not a comparison of totals.

A sparkline connects the points and hides the axes. A jump from 0 to 14 becomes a slope. A spike keeps the zeros on the baseline and draws the 14 as a stem. Spike axes are on unless you turn them off. A sparkline cannot show axes.

For a strip in a table, set both axes to false. The stems stay. The labels go away, which is the right trade when the surrounding row already names the series. Axis titles and grid stay in the playground.

axes off
{
  "axes": { "x": false, "y": false }
}

Data

A plain number array works. The field name is value. X is the index. The smallest spec is three numbers, and the second one is the burst.

Rows are the usual shape when the x has a name. Point encoding.x at the time or the bucket, and encoding.y at the magnitude. Blocked requests uses time and count. Ridge, as spikes uses hour and jolts.

encoding
{
  "data": [
    { "time": "00:00", "count": 1 },
    { "time": "00:05", "count": 0 },
    { "time": "00:10", "count": 8 }
  ],
  "encoding": { "x": "time", "y": "count" }
}

A missing number is skipped. The stem is not drawn for that bucket. Zero is drawn, as a point on the baseline.

a11y.alt is required. One sentence, 10 to 500 characters, with the point of the chart.

A spec that renders

This is the smallest spike. version, type, data, and a11y.alt are required. mark can be omitted. Stems rise from 0. Axes are on. Omit size and the renderer picks a wide, short plot. The docs preview uses the spike card. A size in the spec wins. Ridge, as spikes sets 640 by 280, so the rail uses that size.

spec.json
{
  "version": "1",
  "type": "spike",
  "data": [
    0,
    6,
    1
  ],
  "a11y": {
    "alt": "Hits spike at the second bucket."
  }
}

Install core and the adapter for your framework. The menu in the sidebar picks the snippet. spec is the JSON above.

Import@chartkitdev/core/charts/spikeBundle@chartkitdev/core/allFamilyCore
React
npm install @chartkitdev/core
npm install @chartkitdev/react

import { Chart } from "@chartkitdev/react";

export function Panel() {
  return <Chart spec={spec} />;
}
Vanilla
npm install @chartkitdev/core
npm install @chartkitdev/vanilla

import { mount } from "@chartkitdev/vanilla";

const chart = mount(document.querySelector("#chart"), spec);
chart.update(spec);
Vue
npm install @chartkitdev/core
npm install @chartkitdev/vue

<script setup>
import { Chart } from "@chartkitdev/vue";
</script>

<template>
  <Chart :spec="spec" />
</template>
Svelte
npm install @chartkitdev/core
npm install @chartkitdev/svelte

<script>
  import { Chart } from "@chartkitdev/svelte";
</script>

<Chart {spec} />
Astro
npm install @chartkitdev/core
npm install @chartkitdev/astro

---
import { Chart } from "@chartkitdev/astro";
---

<Chart spec={spec} />
Solid
npm install @chartkitdev/core
npm install @chartkitdev/solid

import { Chart } from "@chartkitdev/solid";

export function Panel() {
  return <Chart spec={spec} />;
}
Qwik
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} />;
});
Angular
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;
}
Custom element
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 between two spike specs. Blocked requests is six five-minute buckets and an explicit baseline of 0. Ridge, as spikes is sixteen hours, with axis titles, a size, and a tooltip that names the jolts.

Baseline

mark.baseline is the value the stems rise from. Omit it and the baseline is 0, which is the right origin for a count. Blocked requests and Ridge, as spikes both set 0. A series that wanders around some other level sets that level here. Stems above the baseline go up. Stems below it go down.

mark.baseline
{
  "mark": { "baseline": 0 }
}

The slider runs from 0 to 12 so the move is easy to see on these examples. The spec accepts any number. Set a baseline outside that range in the playground.

Tooltip

Each stem carries a title with the label and the value. That title is part of the SVG. tooltip is the hover card. It is on when the key is omitted. tooltip: false turns the card off. tooltip: true turns it on.

tooltip false
{
  "tooltip": false
}
tooltip true
{
  "tooltip": true
}

tooltip.fields chooses the rows in the card. Ridge, as spikes names the hour and the jolts. Change those fields in the playground. Turning the card off and on again puts that object back. An example that omitted tooltip gets the key removed.

The rest of the spec

mark.strokeWidth is the stem width in pixels. mark.opacity fades the stems. mark.sampling downsamples a long series and keeps the spikes in each bucket. axes.x.title and axes.y.title name the axes. Ridge, as spikes sets both. A legend is not drawn. Theme presets live on the playground, with the full option list.