Because @carbon/charts expects a window object, you should dynamically import the chart components within Svelte's onMount function to prevent errors during Server-Side Rendering (SSR).
<script>
import '@carbon/charts-svelte/styles.css'
import { onMount } from 'svelte'
let Chart = $state()
onMount(async () => {
const charts = await import('@carbon/charts-svelte')
Chart = charts.BarChartSimple
})
</script>
<Chart
data={[
{ group: 'Qty', value: 65000 },
{ group: 'More', value: 29123 },
{ group: 'Sold', value: 35213 },
{ group: 'Restocking', value: 51213 },
{ group: 'Misc', value: 16932 }
]}
options={{
theme: 'white',
title: 'Simple bar (discrete)',
height: '400px',
axes: {
left: { mapsTo: 'value' },
bottom: { mapsTo: 'group', scaleType: 'labels' }
}
}} />