Zubra UI
Code for
GitHub

line-chart

A price chart: an area under a line, with the high, low and a crosshair that follows the pointer and shows the value under it.

Try it: events appear here (pointhover).

Source: line-chart.zb, and its registry item.

Install

Compiled (any project)
npx shadcn@latest add https://zubra-js.github.io/zubra-ui/r/line-chart.jsonpnpm dlx shadcn@latest add https://zubra-js.github.io/zubra-ui/r/line-chart.jsonyarn dlx shadcn@latest add https://zubra-js.github.io/zubra-ui/r/line-chart.jsonbunx --bun shadcn@latest add https://zubra-js.github.io/zubra-ui/r/line-chart.json
One file, no dependencies (3.1 KB gzipped)
npx shadcn@latest add https://zubra-js.github.io/zubra-ui/r/element/line-chart.jsonpnpm dlx shadcn@latest add https://zubra-js.github.io/zubra-ui/r/element/line-chart.jsonyarn dlx shadcn@latest add https://zubra-js.github.io/zubra-ui/r/element/line-chart.jsonbunx --bun shadcn@latest add https://zubra-js.github.io/zubra-ui/r/element/line-chart.json
.zb source (to edit it with Zubra)
npx shadcn@latest add https://zubra-js.github.io/zubra-ui/r/src/line-chart.jsonpnpm dlx shadcn@latest add https://zubra-js.github.io/zubra-ui/r/src/line-chart.jsonyarn dlx shadcn@latest add https://zubra-js.github.io/zubra-ui/r/src/line-chart.jsonbunx --bun shadcn@latest add https://zubra-js.github.io/zubra-ui/r/src/line-chart.json
No build: a script tag, straight from this site
HTML
<link rel="stylesheet" href="https://zubra-js.github.io/zubra-ui/themes/default.css">
<script type="module" src="https://zubra-js.github.io/zubra-ui/cdn/line-chart.js"></script>

The compiled install writes src/components/zubra/line-chart.js and the theme, and adds @zubra/runtime to your dependencies. The one-file install writes the same path as a plain custom element that needs nothing installed (or download it and load it with a <script type="module">); it's smaller on a page with one to three components, the shared runtime with more.

Usage

index.html
<line-chart label="Price"></line-chart>

<script type="module">
  import './components/zubra/line-chart.js';

  const element = document.querySelector('line-chart');
  element.points = [42.1, 43.8, 41.9, 44.6, 46.2, 45.1, 47.9, 49.3, 48.2, 50.6, 52.4, 51.1];
  element.addEventListener('pointhover', (event) => console.log('pointhover', event.detail));
</script>
Example.jsx
import './components/zubra/line-chart.js';

const points = [42.1, 43.8, 41.9, 44.6, 46.2, 45.1, 47.9, 49.3, 48.2, 50.6, 52.4, 51.1];

export function LineChartExample() {
  return (
    <line-chart
      label="Price"
      points={points}
      onpointhover={(event) => console.log('pointhover', event.detail)}
    ></line-chart>
  );
}
Example.vue
<script setup>
import './components/zubra/line-chart.js';
const points = [42.1, 43.8, 41.9, 44.6, 46.2, 45.1, 47.9, 49.3, 48.2, 50.6, 52.4, 51.1];
const onPointhover = (event) => console.log('pointhover', event.detail);
</script>

<template>
  <line-chart label="Price" :points.prop="points" @pointhover="onPointhover"></line-chart>
</template>

<!-- vite.config.js: vue({ template: { compilerOptions: { isCustomElement: (tag) => tag.includes('-') } } }) -->
Example.svelte
<script>
  import './components/zubra/line-chart.js';
  const points = [42.1, 43.8, 41.9, 44.6, 46.2, 45.1, 47.9, 49.3, 48.2, 50.6, 52.4, 51.1];
</script>

<line-chart
  label="Price"
  {points}
  onpointhover={(event) => console.log('pointhover', event.detail)}
></line-chart>
example.component.ts
import { Component, CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
import './components/zubra/line-chart.js';

@Component({
  selector: 'app-line-chart-example',
  schemas: [CUSTOM_ELEMENTS_SCHEMA],
  template: `
    <line-chart
      label="Price"
      [points]="points"
      (pointhover)="onPointhover($event)"
    ></line-chart>
  `,
})
export class LineChartExample {
  points = [42.1, 43.8, 41.9, 44.6, 46.2, 45.1, 47.9, 49.3, 48.2, 50.6, 52.4, 51.1];

  onPointhover(event: Event) {
    console.log('pointhover', (event as CustomEvent).detail);
  }
}

API

Properties (each is also an HTML attribute of the same name, unless marked)
PropertyTypeDefault
points
property only
unknown[][]
labelstring"Price"
Events
EventWhen
pointhoverThe pointer is over a point; detail is its index, or -1 when it leaves.

Size

1.6 KB gzipped for the component, plus the runtime, which every Zubra component on a page shares (up to 22.1 KB, all of it). On its own, with the parts of the runtime it uses, it's 18.1 KB.

Theme

Every component reads shadcn/ui's CSS variables, so any shadcn theme works. Pick a look or a colour, or paste a theme's CSS.

Look: colours, fonts, corners and motion

Accent colour