Kumo Svelte
  • Home
  • Installation
  • Colors
  • Accessibility
  • Changelog
  • Autocomplete
  • Badge
  • Banner
  • Breadcrumbs
  • Button
  • Checkbox
  • Clipboard Text
  • Cloudflare Logo
  • CodeHighlighted
  • Collapsible
  • Combobox
  • Command Palette
  • Date Picker
  • Dialog
  • Dropdown
  • Empty
  • Flow
  • Grid
  • Input
  • InputArea
  • InputGroup
  • Label
  • Layer Card
  • Link
  • Loader
  • MenuBar
  • Meter
  • Pagination
  • Popover
  • Radio
  • Select
  • Sensitive Input
  • Sidebar
  • Skeleton Line
  • Switch
  • Table
  • Table of Contents
  • Tabs
  • Text
  • Toast
  • Toolbar
  • Tooltip
  • Charts
  • Colors
  • Timeseries
  • Maps
  • Sankey
  • Custom Chart
  • Page Header
  • Resource List
  • Delete Resource
Custom Chart
kumo-svelte

Custom Chart

Example charts using the Chart component.

Custom Chart

Use Chart when you need direct ECharts option control.

<script lang="ts">
  import { Chart, ChartPalette, type KumoChartOption } from "kumo-svelte/components/chart";
  import { echarts } from "../chart-echarts";

  const options = {
    aria: { enabled: true },
    series: [
      {
        type: "pie" as const,
        radius: "70%",
        data: ["Workers", "KV", "R2", "D1"].map((name, index) => ({
          name,
          value: [45, 25, 18, 12][index],
          itemStyle: { color: ChartPalette.categorical(index) },
        })),
      },
    ],
    tooltip: { trigger: "item" as const },
  } satisfies KumoChartOption;
</script>

<Chart {echarts} {options} height={300} />

Custom Tooltip with HTML

For tooltips that require custom HTML formatting, use the dangerousHtmlFormatter property instead of the standard ECharts formatter. This makes the security implications more explicit.

When using dangerousHtmlFormatter, sanitize any user-provided content using echarts.format.encodeHTML to prevent XSS vulnerabilities.

<script lang="ts">
  import { Chart, ChartPalette, type KumoChartOption } from "kumo-svelte/components/chart";
  import { echarts } from "../chart-echarts";

  const options = {
    aria: { enabled: true },
    series: [
      {
        type: "pie" as const,
        radius: ["45%", "70%"],
        data: ["Workers", "KV", "R2", "D1"].map((name, index) => ({
          name,
          value: [45, 25, 18, 12][index],
          itemStyle: { color: ChartPalette.categorical(index) },
        })),
      },
    ],
    tooltip: {
      trigger: "item" as const,
      dangerousHtmlFormatter: (params) => {
        const item = Array.isArray(params) ? params[0] : params;
        const name = typeof item?.name === "string" ? item.name : "";
        const value = typeof item?.value === "number" ? item.value : 0;
        return `<strong>${echarts.format.encodeHTML(name)}</strong><br>${value}%`;
      },
    },
  } satisfies KumoChartOption;
</script>

<Chart {echarts} {options} height={300} />

API Reference

PropTypeDescription
echartstypeof echartsRegistered ECharts module instance.
optionsKumoChartOptionECharts options.
heightnumberChart height in pixels.
isDarkModebooleanUses the dark chart palette.
onEventsPartial<ChartEvents>ECharts event handlers.
optionUpdateBehaviorSetOptionOptsECharts setOption behavior.
refECharts \| nullBindable chart instance.

On this page

  • Custom Chart
  • Custom Tooltip with HTML
  • API Reference