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
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
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
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
<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
<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>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>
);
}<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('-') } } }) --><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>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
| Property | Type | Default |
|---|---|---|
pointsproperty only | unknown[] | [] |
label | string | "Price" |
| Event | When |
|---|---|
pointhover | The 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.