首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Vue-Chartjs不渲染图形

Vue-Chartjs不渲染图形
EN

Stack Overflow用户
提问于 2021-09-05 14:30:46
回答 1查看 438关注 0票数 1

我正在用laravel建立一个网站,并使用vuejs来管理前端。我想通过vue-chartjs显示几个图表,但是即使数据成功传递,vue-chartjs也没有显示图表。我一直在关注他们的网站指南,但图表从来没有显示出来。

我的Vue组件

代码语言:javascript
复制
<teplate>
    <div>
      ...
    <line-chart :chart-data="datacollection"></line-chart>
    <button @click="fillData()">Randomize</button>
    </div>
</template>

<script>
import Table from '../equipments/table.vue'
import LineChart from '../equipments/LineChart.js'
import DropDownList from '../equipments/dropdownlist.vue'
    export default {
    data () {
      return {
        datacollection: null
      }
    },
        components: {
            LineChart,
            Table,
            DropDownList
        },
    mounted () {
      this.fillData()
    },
    methods: {
      fillData () {
        this.datacollection = {
          labels: ['weqw','wewq'],
          datasets: [
            {
              label: 'Data One',
              backgroundColor: '#f87979',
              data: [this.getRandomInt(), this.getRandomInt()]
            }, 
            {
              label: 'Data One',
              backgroundColor: '#f87979',
              data: [this.getRandomInt(), this.getRandomInt()]
            }
          ]
        }
      },
      getRandomInt () {
        return Math.floor(Math.random() * (50 - 5 + 1)) + 5
      }
    }
  }
</script>

<style>
  .small {
    max-width: 600px;
    margin:  150px auto;
  }
</style>

我的Chart.js

代码语言:javascript
复制
import { Line, mixins } from 'vue-chartjs'
const { reactiveProp } = mixins

export default {
  extends: Line,
  mixins: [reactiveProp],
  props: ['options'],
  mounted () {
    // this.chartData is created in the mixin.
    // If you want to pass options please create a local options object
    this.renderChart(this.chartData, this.options)
  }
}

希望能在这里收到一些提示,提前谢谢

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-09-05 17:46:53

Vue-chartjs仅适用于chart.js的v2。因此,如果您想使用2.9.4,则需要将chart.js降级到它的版本。

npm i chart.js@2.9.4

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/69064301

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档