Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add example for nuxt3 (ssr) to the documentation #97

Open
Rednas83 opened this issue Feb 20, 2024 · 4 comments
Open

Add example for nuxt3 (ssr) to the documentation #97

Rednas83 opened this issue Feb 20, 2024 · 4 comments

Comments

@Rednas83
Copy link

After exactly following the instruction I am getting
image

Tried wrapping apexchart component in ClientOnly component but that didn't fix the issue

  <ClientOnly>
    <div>
      <apexchart width="500" type="bar" :options="chartOptions" :series="series"></apexchart>
    </div>
  </ClientOnly>

Anyone has a fix for nuxt3?

@Sebarkar
Copy link

Change the plugin file name to *.client.ts

@Rednas83
Copy link
Author

Just tried with a javascript plugin because for typescript we will need to wait for official support or for an external declaration file🤞

plugins/apex.client.js

import VueApexCharts from "vue3-apexcharts";
export default defineNuxtPlugin((nuxtApp) => {
  nuxtApp.vueApp.use(VueApexCharts)
})

components/vchart.vue

<template>
  <ClientOnly>
    <apexchart width="500" type="bar" :options="options" :series="series"></apexchart>
  </ClientOnly>
</template>

<script setup lang="ts">
const options = ref({
  chart: {
    id: "vuechart-example",
  },
  xaxis: {
    categories: [1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998],
  },
})
const series = ref([
  {
    name: "series-1",
    data: [30, 40, 45, 50, 49, 60, 70, 91],
  },
])
</script>

Unfortunately this is also not working😢
Terminal
image
Console
image

Any more ideas?

@Rednas83 Rednas83 changed the title Window is not defined with nuxt3 Add support for nuxt3 (ssr) Mar 29, 2024
@Sebarkar
Copy link

Sebarkar commented Mar 29, 2024

import VueApexCharts from 'vue3-apexcharts'

export default defineNuxtPlugin(nuxtApp => {
    nuxtApp.vueApp.use(VueApexCharts) // missed
    return {
        provide: {
            charts: VueApexCharts,
        }
    }
})

@Rednas83
Copy link
Author

Rednas83 commented Mar 30, 2024

Got it working😀 The ungroup error was caused by a conflicting custom ungroup function. Also don't forget to wrap apexchart with ClientOnly to avoid a hydration mismatch
image
plugins/apex.client.js

import VueApexCharts from "vue3-apexcharts";
export default defineNuxtPlugin((nuxtApp) => {
  nuxtApp.vueApp.use(VueApexCharts)
})

components/vchart.vue

<template>
  <h2>Charting with apex</h2>
  <ClientOnly>
    <apexchart width="500" type="bar" :options="options" :series="series"></apexchart>
  </ClientOnly>
</template>

<script setup lang="ts">
const options = ref({
  chart: {
    id: "vuechart-example",
  },
  xaxis: {
    categories: [1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998],
  },
})
const series = ref([
  {
    name: "series-1",
    data: [30, 40, 45, 50, 49, 60, 70, 91],
  },
])
</script>

Perhaps this example can also be added to the docs for nuxt users?

@Rednas83 Rednas83 changed the title Add support for nuxt3 (ssr) Add example for nuxt3 to the documentation (ssr) Mar 30, 2024
@Rednas83 Rednas83 changed the title Add example for nuxt3 to the documentation (ssr) Add example for nuxt3 (ssr) to the documentation Mar 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants