前提
chart.jsを使用したいため、インストール後に表示させようとするもエラーが出てしまう。
vue-chart.jsのHPより参考して、vue-chart.jsをインストトールしている。
現在のバージョン
"vue": ^2.6.11
"vue-chartjs": "^4.1.1"
"chart.js": "2.9.4"
yarn add vue-chartjs chart.js@2.9.4
発生しているエラー
index.js?368d:85 Uncaught TypeError: Object(...) is not a function at generateChart (index.js?368d:85:1) at eval (index.js?368d:232:1) at ./node_modules/vue-chartjs/dist/index.js (chunk-vendors.js:22240:1) at __webpack_require__ (app.js:849:30) at fn (app.js:151:20) at eval (cjs.js?!./node_modules/vue-loader/lib/index.js?!./src/views/store/Chart.vue?vue&type=script&lang=js&:3:69) at ./node_modules/cache-loader/dist/cjs.js?!./node_modules/vue-loader/lib/index.js?!./src/views/store/Chart.vue?vue&type=script&lang=js& (app.js:1694:1) at __webpack_require__ (app.js:849:30) at fn (app.js:151:20) at eval (Chart.vue?4c7e:1:1)
Index.vueから子Chart.vueを表示させる。
vue-chart.jsを利用したかったが、表示することができずタイトルのエラーが出てしまう。
エラーを解消してグラフを表示させたのですが、エラー解消できません。
どなたかご教授していただければと思います。
Index.vueにChart.vueを表示させる。
コンポーネント: Chart.vue
Chart.vue
1<script> 2import { Bar } from 'vue-chartjs' 3 4export default { 5 extends: Bar, 6 data: () => ({ 7 chartdata: { 8 datacollection: { 9 labels: ['January', 'February'], 10 datasets: [ 11 { 12 label: 'Data One', 13 backgroundColor: '#f87979', 14 data: [40, 20] 15 } 16 ] 17 } 18 }, 19 options: { 20 responsive: true, 21 maintainAspectRatio: false 22 } 23 }), 24 25 mounted () { 26 this.renderChart(this.datacollection, this.options) 27 } 28} 29</script> 30<style> 31</style>
Index.vue
1<template> 2 <v-container> 3 <Chart /> 4 </v-container> 5</template> 6 7<script lang="ts"> 8import Vue from 'vue' 9import Chart from './Chart.vue' 10 11export default Vue.extend({ 12 name: 'Index', 13 components: { 14 Chart 15 }, 16 data () { 17 return { 18 counter: 0, 19 btnName: '追加', 20 chartData: { 21 labels: [], 22 // データ詳細 23 datasets: [ 24 { 25 label: 'データ', 26 data: [] 27 } 28 ] 29 }, 30 options: { 31 }, 32 addFlag: false 33 } 34 } 35}) 36</script> 37<style scoped> 38</style> 39 40import Vue from 'vue' 41import './plugins/axios' 42import App from './App.vue' 43 44Vue.config.productionTip = false 45 46 47new Vue({ 48 router, 49 store, 50 vuetify, 51 render: h => h(App) 52}).$mount('#app') 53
あなたの回答
tips
プレビュー