A Nuxt module for Wick Charts. It registers the @wick-charts/vue components and composables, so a page uses charts with no imports. For chart blocks themed by shadcn-vue, see the shadcn-vue blocks.
01 — ADD THE MODULE
Run
npx nuxi module add @wick-charts/nuxt. It installs the package and adds it to modules in nuxt.config.ts. The module brings @wick-charts/vue with it.export default defineNuxtConfig({ modules: ['@wick-charts/nuxt'],});02 — USE THE COMPONENTS
Every component has a
Wick prefix: ChartContainer becomes <WickChartContainer>, Tooltip becomes <WickTooltip>. The prefix keeps short names such as Title and Legend apart from your own components. Import types, themes and helpers from @wick-charts/vue. The chart fills its parent, so give the parent a height.<script setup lang="ts">import type { OHLCData } from '@wick-charts/vue'; const { data: candles } = await useFetch<OHLCData[]>('/api/candles');</script> <template> <div style="height: 400px"> <WickChartContainer> <WickCandlestickSeries :data="candles ?? []" /> <WickCrosshair /> <WickTooltip /> <WickYAxis /> <WickTimeAxis /> </WickChartContainer> </div></template>03 — SERVE THE DATA
A server route returns the rows. A candle is
{ time, open, high, low, close, volume? }, with time in milliseconds: a Date becomes a string on its way through JSON. A line or bar series takes { time, value }.// server/api/candles.tsimport type { OHLCData } from '@wick-charts/vue'; const HOUR = 3_600_000; // A random walk. Read your database or exchange API here.export default defineEventHandler((): OHLCData[] => { const start = Date.now() - 200 * HOUR; let close = 100; return Array.from({ length: 200 }, (_, i) => { const open = close; close = open + (Math.random() - 0.5) * 4; return { time: start + i * HOUR, open, high: Math.max(open, close) + Math.random(), low: Math.min(open, close) - Math.random(), close, }; });});04 — COMPOSABLES WITH NO IMPORT
useChartInstance, useVisibleRange, useYRange, useLastYValue, usePreviousClose and useCrosshairPosition are auto-imported. Call them in a component inside <WickChartContainer>, and give the series they read an id. Import useTheme from @wick-charts/vue: Vuetify and other UI kits auto-import the same name.<!-- components/PriceTitle.vue --><script setup lang="ts">const chart = useChartInstance();const last = useLastYValue(chart, 'price');</script> <template> <WickTitle>BTC {{ last?.value.toFixed(2) }}</WickTitle></template> <!-- in the page: the series needs the id --><WickChartContainer> <PriceTitle /> <WickCandlestickSeries id="price" :data="candles ?? []" /></WickChartContainer>05 — SERVER RENDERING
The chart draws on a canvas in the browser, after hydration. On the server, Nuxt renders the chart container with its size and theme background, so the page does not jump when the chart appears. You do not need a
<ClientOnly> wrapper. useFetch on the server puts every row into the HTML payload: 1,500 candles add about 290 kB, and Nuxt dev warns about the size. For a long series, fetch in the browser with server: false.<script setup lang="ts">import type { OHLCData } from '@wick-charts/vue'; // Thousands of rows: fetch them in the browser, so they stay out of the HTML.const { data: candles } = useFetch<OHLCData[]>('/api/candles', { server: false });</script>06 — OPTIONS
Set a different component prefix, or turn off the composable auto-imports. A prefix applies to every name,
ChartContainer too. An empty prefix gives the bare names, and then <Title> is Nuxt's head component, not the chart title. The module warns at build time when another component takes one of its names. The module works with Nuxt 3.12 and later, and with Nuxt 4.export default defineNuxtConfig({ modules: ['@wick-charts/nuxt'], wickCharts: { prefix: 'Chart', // <ChartChartContainer>, <ChartLineSeries>, <ChartTooltip> composables: false, },});