OoxmlChart
Draws a chart from a chart model, without opening a document.
import { OoxmlChart } from '@tumblerjs/svelte';
Example
Loading…
Change the chart type to see the same data as columns, a line, a pie or a doughnut.
ChartPreview.svelte
<script lang="ts">
import type { SupportedChartModel } from '@tumblerjs/charts';
import { OoxmlChart } from '@tumblerjs/svelte';
type Kind = 'column' | 'line' | 'pie' | 'doughnut';
let kind = $state<Kind>('column');
let width = $state(600);
const green = { kind: 'rgb', value: '#4d8060' } as const;
const points = <T,>(values: T[]) =>
values.map((value, index) => ({ index, value }));
let model: SupportedChartModel = $derived({
status: 'supported',
kind,
title: 'Quarterly deliveries',
titleFormula: undefined,
legend: { position: 'bottom', overlay: false },
grouping: 'standard',
holeSize: 55,
axes: [],
series: [{
index: 0,
order: 0,
title: 'Deliveries',
titleFormula: undefined,
categories: {
kind: 'string',
formula: undefined,
formatCode: undefined,
points: points(['Q1', 'Q2', 'Q3', 'Q4']),
},
values: {
kind: 'number',
formula: undefined,
formatCode: undefined,
points: points([24, 38, 31, 52]),
},
fill: green,
line: green,
}],
});
</script>
<label>
Chart type
<select bind:value={kind}>
<option value="column">Column</option>
<option value="line">Line</option>
<option value="pie">Pie</option>
<option value="doughnut">Doughnut</option>
</select>
</label>
<div class="chart" bind:clientWidth={width}>
<OoxmlChart
{model}
width={Math.max(240, width)}
height={280}
/>
</div>
<style>
label {
display: flex;
align-items: center;
gap: 10px;
margin-bottom: 16px;
}
.chart {
background: white;
color: #18261d;
min-width: 0;
overflow: hidden;
}
</style>
Usage
Build a SupportedChartModel (exported by @tumblerjs/charts), or pass a chart from a parsed document. width and height set the chart's layout, and the component stretches to fill its container, so pass the container's size. The example binds clientWidth and keeps a fixed height. Charts Tumbler cannot draw come through as UnsupportedChartModel, and the component shows a "Chart preview unavailable" placeholder instead.
Props
| Prop | Description |
|---|---|
modelrequired ChartModel | The chart to draw: its type, series, axes and legend. |
widthrequired number | Width the chart is laid out at, in CSS pixels. Pass the container's width. |
heightrequired number | Height the chart is laid out at, in CSS pixels. Pass the container's height. |
resolveColor (color: ChartColor) => string | undefined | Turns a theme colour reference into a CSS colour. |
formatNumber (value: number, formatCode: string | undefined) => string | Formats axis and label numbers, given the chart's number format code when it has one. |