You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The chart will still render without client-only however the client side DOM tree will no longer match the server render and a console error will be shown.
Multi chart example
You can add multiple Chart.js types to your chart.js plugin file like so:
import Vue from 'vue'
import { Line } from 'vue-chartjs'
import { Pie } from 'vue-chartjs'
Vue.component('line-chart', {
extends: Line,
props: ['data', 'options'],
mounted () {
this.renderChart(this.data, this.options)
}
})
Vue.component('pie-chart', {
extends: Pie,
props: ['data', 'options'],
mounted () {
this.renderChart(this.data, this.options)
}
})
@aivaras-ciurlionis Hmm I'm using pretty much the same code and exactly the same versions of Nuxt and Chart.js but can't modify options of any chart. For instance - if I pass in to hide the legend, it ignores it and uses default. Did you experience the same issue?
@aivaras-ciurlionis Hmm I'm using pretty much the same code and exactly the same versions of Nuxt and Chart.js but can't modify options of any chart. For instance - if I pass in to hide the legend, it ignores it and uses default. Did you experience the same issue?
@WesThorburn Thanks for sharing the instruction. They are great starting point, especially for front-end newbie like me :)
I encountered few issues and below is how they got resolved. Perhaps these issues are resulted from changes / new requirement introduced in recent versions, just my guess.
During runtime I was getting error complaining that required props chartData is missing.
My solution: rename the data props as chartData.
The chart background and axis (incl. axis scale) were displayed properly, but the data line was not coming.
My solution: within the chartData object, in addition to datasets, add a labels array, each element is the label for a data point.
Voila!
I still need to explore more especially customisation of the chart.
BTW, may I know why it has to be implemented as Nuxt plugin rather than standard Vue component?
Initially I tried to implement the chart as Vue component, but the import statement (from vue-chartjs/legacy) seems to cause runtime error Cannot use import statement outside a module. When I search this error message in google, some responses in StackOverflow suggest to implement thing as Nuxt plugin instead of component. Eventually I landed on this page.
This worked well for me with everyone's tips. I had to remove <client-only>...</client-only> .. it was causing some screwy page rendering behavior. My charts were showing up only after saving my Nuxt project, but not on a page refresh. Removing that resolved the issue for me and I haven't noticed any problems or console errors without it
I'm using chartsjs in markdown files with embedded Vue components.
I'm getting this error:
ERROR in ./node_modules/vue-chartjs/dist/index.js 216:37
Module parse failed: Unexpected token (216:37)
You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders
| const ref = shallowRef(null);
| const reforwardRef = (chartRef)=>{
I'm getting this error: ERROR in ./node_modules/vue-chartjs/dist/index.js 216:37 Module parse failed: Unexpected token (216:37) You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders | const ref = shallowRef(null); | const reforwardRef = (chartRef)=>{
ref.value = chartRef?.chart;
| }; | expose({
package.json
"nuxt": "^2.15.8", "vue": "^2.7.10",
you have to use this versions
{
...
"dependencies": {
"chart.js": "2.9.4",
"vue-chartjs": "^3.5.1"
}
...
}
Thanks buddy, nice and clear ... one thing though, now you have to specify a version to
[email protected]
cause3.x
is not compatiable. Cheers!`