z-chart
Chart component family: bar, line, area, pie, donut, radar, sparkline and GeoJSON choropleth map. SVG and Canvas dual engines, tooltip, legend and enter animations.
Bar
Bar chart with legend toggle, hover tooltip, canvas rendering and mixed bar+line dual-axis series.
Categories
<z-chart type="bar" title="Monthly Revenue" width="620" height="300">
<z-chart-axis position="bottom" type="category" title="Month"></z-chart-axis>
<z-chart-axis position="left" type="value" format="currency"></z-chart-axis>
<z-chart-series name="Online"></z-chart-series>
<z-chart-series name="Retail"></z-chart-series>
<z-chart-series name="Wholesale"></z-chart-series>
</z-chart>
// data 是 DOM property(attribute 不生效),需 JS 设置:
const series = document.querySelector("z-chart-series");
series.data = [{ label: "Jan", value: 4200 }, { label: "Feb", value: 5100 }];
Mixed Series & Dual Axis
<z-chart type="bar" title="Revenue vs Growth" width="620" height="300" renderer="canvas">
<z-chart-axis position="bottom" type="category" title="Quarter"></z-chart-axis>
<z-chart-axis position="left" type="value" title="Revenue" format="currency"></z-chart-axis>
<z-chart-axis position="right" type="value" title="Growth %" format="percent"></z-chart-axis>
<z-chart-series name="Revenue" type="bar"></z-chart-series>
<z-chart-series name="Growth" type="line" y-axis="right"></z-chart-series>
</z-chart>
Line & Area
Trend charts with enter animation. Click the legend to hide series.
<z-chart type="line" title="Weekly Active Users" width="620" height="260">
<z-chart-axis position="bottom" type="category" title="Week"></z-chart-axis>
<z-chart-axis position="left" type="value"></z-chart-axis>
<z-chart-series name="Desktop"></z-chart-series>
<z-chart-series name="Mobile"></z-chart-series>
</z-chart>
// 数字数组也可直接作为 series.data:
series.data = [12, 18, 16, 24, 22, 30, 28, 36];
<z-chart type="area" title="Downloads" width="620" height="260">
<z-chart-series name="App Store"></z-chart-series>
<z-chart-series name="Google Play"></z-chart-series>
</z-chart>
// 不写 z-chart-axis 时自动生成分类 x 轴与数值 y 轴
Pie & Donut
Share of total. Donut shows the total in the center; the canvas renderer falls back to SVG.
<z-chart type="pie" title="Traffic Sources" width="340" height="300">
<z-chart-series name="Traffic"></z-chart-series>
</z-chart>
// 饼图仅支持 SVG 渲染(renderer="canvas" 自动回退)
series.data = [{ label: "Organic", value: 45 }, { label: "Paid", value: 25 }];
<z-chart type="donut" title="Budget Allocation" width="340" height="300">
<z-chart-series name="Budget"></z-chart-series>
</z-chart>
// type="donut" 时中心显示合计;环形图仅支持 SVG 渲染(canvas 自动回退)
series.data = [{ label: "Engineering", value: 320 }, { label: "Marketing", value: 180 }];
Radar
Multi-axis profile. Each axis is normalized by the largest value across series, so axes can carry different units (¥, cups, %). Series sharing an axis must be the same metric (store vs region average, this year vs last) — two different metrics in one radar squash the smaller one. Fewer than 3 axes is treated as no data.
<z-chart type="radar" title="Store Profile: Binjiang vs Region Average" width="440" height="360">
<z-chart-series name="滨江店"></z-chart-series>
<z-chart-series name="区域均值"></z-chart-series>
</z-chart>
// 每个系列一组 {label, value};label 即轴名,各系列顺序必须一致
shop.data = [{ label: "营业额", value: 128000 }, { label: "出杯量", value: 820 }, { label: "客单价", value: 32.5 }, { label: "实收率", value: 0.86 }, { label: "复购率", value: 0.42 }, { label: "达成率", value: 1.08 }];
// 逐轴归一:每根轴的分母是「所有系列在该轴上的最大值」→ 顶点越靠外 = 该轴越强
// 系列必须是同一指标的不同主体(本店 vs 区域均值);销售额与订单数混在一张雷达里,小的会被压到圆心
<z-chart type="radar" title="Store Inspection Score" width="400" height="340">
<z-chart-series name="巡检得分"></z-chart-series>
</z-chart>
// 单系列:分母取「全图最大值」(此处 92)—— 最外圈是它,不是满分 100
series.data = [{ label: "服务", value: 92 }, { label: "出杯速度", value: 78 }, { label: "卫生", value: 85 }, { label: "陈列", value: 66 }, { label: "客诉处理", value: 88 }];
Sparkline
Compact single-series trend, ideal for CPU and latency monitoring.
<z-chart type="sparkline" title="CPU %" width="280" height="48" legend="false" show-grid="false">
<z-chart-series name="CPU"></z-chart-series>
</z-chart>
// 迷你图默认高度 48px,单系列折线 + 渐变填充
series.data = [22, 18, 25, 30, 28, 35, 32, 40];
<z-chart type="sparkline" title="Latency (ms)" width="280" height="48" legend="false" show-grid="false">
<z-chart-series name="Latency"></z-chart-series>
</z-chart>
// 迷你图只画单系列,适合 CPU/延迟等指标监控
series.data = [120, 95, 110, 88, 130, 105, 92, 118];
Map
GeoJSON choropleth: pass your own GeoJSON, region values drive the color scale.
<z-chart type="map" title="Regional Sales" width="620" height="360"></z-chart>
// geojson / values 是 DOM property(attribute 不生效),需 JS 设置:
chart.geojson = { type: "FeatureCollection", features: [...] };
chart.values = { north: 1200, east: 3400, south: 2100, west: 980, center: 2600 };
API Reference
Properties
| Property | Type | Default | Description |
|---|---|---|---|
type | string | "bar" | Chart type: bar, line, area, pie, donut, sparkline, map |
renderer | string | "svg" | Render engine: svg or canvas (pie/donut/sparkline always SVG) |
width / height | string | "auto" | Size: "auto" or a pixel string like "600" |
title | string | "" | Chart title (also used as aria-label) |
legend | boolean | true | Show legend |
tooltip | boolean | true | Enable hover tooltip |
animation | boolean | true | Enter animation (respects prefers-reduced-motion) |
show-grid | boolean | true | Show grid lines |
locale | string | "en-US" | Locale for number and date formatting |
colors | string[] | null | Custom categorical palette (hex array) |
geojson | object | null | GeoJSON FeatureCollection for choropleth map |
values | object | array | null | Region values: {id: value} or [{id, value}] |
projection | string | "auto" | Map projection: auto, equirectangular, mercator, none |
map-id-key | string | "id" | Property key used to match region id with values |
map-name-key | string | "name" | Property key used as region display name |
z-chart-series (child element)
| Property | Type | Description |
|---|---|---|
name | string | Series display name (legend and tooltip) |
type | string | Series kind: auto (inherits chart type), bar, line, area |
data | array | Series data: numbers, {value}, {label, value} or {x, value} |
color | string | Series color (defaults to the categorical palette) |
y-axis | string | Bind to left or right axis |
format | string | Value format: "auto", "percent", "currency" or a template with {value} |
visible | boolean | Series visibility (toggled by the legend) |
z-chart-axis (child element)
| Property | Type | Description |
|---|---|---|
position | string | Axis position: bottom (x), left (y), right (secondary y) |
type | string | Axis kind: auto, category, value, time |
title | string | Axis title |
min / max | number | Explicit min / max (only applied when the attribute is present) |
tick-count | number | Approximate tick count (0 = automatic) |
grid | boolean | Override the chart show-grid for this axis |
Events
| Event | Detail | Description |
|---|---|---|
z-ready | { type, width, height } | Fired once after first layout |
z-resize | { width, height } | Fired when the chart size changes |
z-tooltip-change | { visible, seriesIndex, dataIndex, label, values } | Fired when tooltip shows/hides |
z-series-toggle | { index, name, visible, hidden } | Fired when a legend item is toggled |
z-marker-click | { seriesIndex, dataIndex, value, formatted } | Fired when a data marker is clicked |