ChartJS 使用VUE 3中的VUE图表:createElement不是函数

r7s23pms  于 2022-11-06  发布在  Chart.js
关注(0)|答案(2)|浏览(372)

我使用的是Vue.js 3,但由于以下错误,我无法使用Vue-chartjs制作图表:

  1. Uncaught TypeError: createElement is not a function
  2. at Proxy.render (BaseCharts.js?86fc:8)
  3. at renderComponentRoot (runtime-core.esm-bundler.js?5c40:673)
  4. at componentEffect (runtime-core.esm-bundler.js?5c40:4475)
  5. at reactiveEffect (reactivity.esm-bundler.js?a1e9:42)
  6. at effect (reactivity.esm-bundler.js?a1e9:17)
  7. at setupRenderEffect (runtime-core.esm-bundler.js?5c40:4458)
  8. at mountComponent (runtime-core.esm-bundler.js?5c40:4416)
  9. at processComponent (runtime-core.esm-bundler.js?5c40:4376)
  10. at patch (runtime-core.esm-bundler.js?5c40:3991)
  11. at mountChildren (runtime-core.esm-bundler.js?5c40:4180)

这是显示我的图表的应用程序:

  1. <template>
  2. <line-chart />
  3. </template>
  4. <script>
  5. import LineChart from "./components/Chart";
  6. export default {
  7. name: "App",
  8. components: {
  9. LineChart
  10. }
  11. };
  12. </script>

这是一个呈现折线图的Chart.vue:

  1. <script>
  2. import { Line } from "vue-chartjs";
  3. export default {
  4. extends: Line,
  5. data: () => ({
  6. chartdata: {
  7. labels: ["January", "February"],
  8. datasets: [
  9. {
  10. label: "Data One",
  11. backgroundColor: "#f87979",
  12. data: [40, 20]
  13. }
  14. ]
  15. },
  16. options: {
  17. responsive: true,
  18. maintainAspectRatio: false
  19. }
  20. }),
  21. mounted() {
  22. this.renderChart(this.chartdata, this.options);
  23. }
  24. };
  25. </script>

我已经用各种形式的数据尝试过这一点,但显然,问题在别处。我必须等待vue.js 3生态系统变得更加完整吗?

9q78igpj

9q78igpj1#

2022年更新

该库现在支持vue 3,您可以按如下方式安装:

  1. pnpm add vue-chartjs chart.js
  2. # or
  3. yarn add vue-chartjs chart.js
  4. # or
  5. npm i vue-chartjs chart.js

"旧答案"
根据此issue,此库尚不支持Vue 3,此错误的根源可在此处解释:
在VUE 2中,我们执行以下操作来创建渲染函数:

  1. export default {
  2. render(createElement ) { // createElement could be written h
  3. return createElement('div')
  4. }
  5. }

在Vue 3中:

  1. import { h } from 'vue'
  2. export default {
  3. render() {
  4. return h('div')
  5. }
  6. }

这意味着createElement未定义

展开查看全部
rdlzhqv9

rdlzhqv92#

https://github.com/apertureless/vue-chartjs
Vue图表似乎未准备好用于vue3
兼容性

  1. v1 later @legacy
  2. Vue.js 1.x
  3. v2 later
  4. Vue.js 2.x

关于vue3的讨论在这里:https://github.com/apertureless/vue-chartjs/issues/601和此处:https://github.com/apertureless/vue-chartjs/issues/637

相关问题