Nuxt Plotly Module (nuxt-plotly - npm)
nuxt-plotly
module is thin Nuxt3 wrapper for [plotly.js]
Features
- All plotly.js methods and events
- Auto redraw on screensize changes and props update
- Data reactivity
- TypeScript support
Require client-side
There are two ways to use the nuxt-plotly
module on the client-side in Nuxt3:
- Wrap the component with the
<client-only>
tag.
<client-only>
<nuxt-plotly
:data="pieChart.data"
:layout="pieChart.layout"
:config="pieChart.config"
style="width: 100%"
></nuxt-plotly>
</client-only>
- Create a file with the
.client.vue
extension, for example,PlotlyPieChart.client.vue
and then you can use the component without the<client-only>
tag.
Quick Setup
- Add
nuxt-plotly
dependency to your project
# Using pnpm
pnpm add -D nuxt-plotly
# Using yarn
yarn add --dev nuxt-plotly
# Using npm
npm install --save-dev nuxt-plotly
- Add
nuxt-plotly
to themodules
section ofnuxt.config.ts
export default defineNuxtConfig({
modules: ["nuxt-plotly"],
});
- Add
plotly.js-dist-min
to thevite.optimizeDeps.include
section ofnuxt.config.ts
export default defineNuxtConfig({
vite: {
optimizeDeps: {
include: ["plotly.js-dist-min"],
},
},
});
Thatβs it! You can now use Nuxt Plotly Module in your Nuxt app