Skip to content

Frameworks ​

The host element must have a height, and the spec should be memoised: a new object draws the chart again.

React ​

tsx
import { useMemo, useRef } from 'react';
import { Chart } from 'nervure/react';

export function Orders({ rows }) {
  const chart = useRef(null);
  const spec = useMemo(() => ({
    type: 'xy', categories: rows.map((r) => r.month),
    series: [{ name: 'Orders', kind: 'bar', data: rows.map((r) => r.count) }],
  }), [rows]);
  return <Chart spec={spec} style={{ height: 300 }} onReady={(c) => { chart.current = c; }} />;
}

Next.js ​

The same component. nervure/react is already marked 'use client', so it can be imported from a server component as long as the spec holds no function.

tsx
// app/page.tsx
import { Chart } from 'nervure/react';

export default async function Page() {
  const data = await getOrders();
  return <Chart spec={{ type: 'pie', data }} style={{ height: 300 }} />;
}

Vue ​

vue
<script setup>
import { NervureChart } from 'nervure/vue';
const spec = { type: 'gauge', value: 64, unit: ' %' };
</script>

<template>
  <div style="height: 300px"><NervureChart :spec="spec" @ready="(chart) => {}" /></div>
</template>

Nuxt ​

vue
<ClientOnly><div style="height: 300px"><NervureChart :spec="spec" /></div></ClientOnly>

Svelte and SvelteKit ​

svelte
<script>
  import { chart } from 'nervure/svelte';
  let { spec } = $props();
</script>

<div use:chart={{ spec }} style="height: 300px"></div>

Angular ​

ts
import { Component, CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
import 'nervure/element';

@Component({
  selector: 'app-orders',
  schemas: [CUSTOM_ELEMENTS_SCHEMA],
  template: `<nervure-chart [spec]="spec" style="height: 300px"></nervure-chart>`,
})
export class OrdersComponent {
  spec = { type: 'funnel', data: [{ name: 'Visitors', value: 5200 }, { name: 'Customers', value: 310 }] };
}

Solid, Astro, Lit, Ember, HTMX, plain HTML ​

Use the web component:

html
<script type="module">import 'nervure/element';</script>
<nervure-chart style="height: 300px" spec='{"type":"gauge","value":64,"unit":" %"}'></nervure-chart>

From code, set the property: element.spec = {…}. It fires ready, with the chart in event.detail.

MIT License