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

我的Vue组件
<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
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)
}
}希望能在这里收到一些提示,提前谢谢
发布于 2021-09-05 17:46:53
Vue-chartjs仅适用于chart.js的v2。因此,如果您想使用2.9.4,则需要将chart.js降级到它的版本。
npm i chart.js@2.9.4
https://stackoverflow.com/questions/69064301
复制相似问题