cod*_*ess 2 javascript vue.js vue-chartjs
MyChart.vue
<template>
<v-container>
<v-card elevation="2">
<v-card-title>AQI Comparison</v-card-title>
<line-chart :chart-data="datacollection"></line-chart>
</v-card>
</v-container>
</template>
<script>
import LineChart from "./LineChart.js";
export default {
name: "AQIChartComponent",
components: {
LineChart
},
data() {
return {
datacollection: {
labels: [
"week 1",
"week 2",
"week 3",
"week 4",
"week 5",
"week 6",
"week 7",
"week 8",
"week 9",
"week 10",
],
datasets: [
{
data: [86, 114, 106, 106, 107, 111, 133, 221, 783, 2478],
label: "Africa",
borderColor: "#3e95cd",
fill: false,
},
{
data: [282, 350, 411, 502, 635, 809, 947, 1402, 3700, 5267],
label: "Asia",
borderColor: "#8e5ea2",
fill: false,
},
{
data: [168, 170, 178, 190, 203, 276, 408, 547, 675, 734],
label: "Europe",
borderColor: "#3cba9f",
fill: false,
},
{
data: [40, 20, 10, 16, 24, 38, 74, 167, 508, 784],
label: "Latin America",
borderColor: "#e8c3b9",
fill: false,
},
{
data: [6, 3, 2, 2, 7, 26, 82, 172, 312, 433],
label: "North America",
borderColor: "#c45850",
fill: false,
},
],
}
};
}
};
</script>
Run Code Online (Sandbox Code Playgroud)
折线图.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)
}
}
Run Code Online (Sandbox Code Playgroud)
我收到以下错误:
[Vue warn]: Error in mounted hook: "TypeError: chart_js__WEBPACK_IMPORTED_MODULE_0__.default is not a constructor"
found in
---> <LineChart>
<VCard>
<AQIChartComponent> at src/components/AQIChartComponent.vue
<AQIComponent> at src/components/AQIComponent.vue
<VMain>
<VApp>
<App> at src/App.vue
<Root>
TypeError: chart_js__WEBPACK_IMPORTED_MODULE_0__.default is not a constructor
Run Code Online (Sandbox Code Playgroud)
我什至将属性从 :chart-data 更改为 :chartData 但它是相同的错误。我正在使用他们文档中的示例代码,我在这里做错了什么?
从错误来看,我认为是vue-chartjs和chart.js之间不兼容的问题
vue-chartjs 自 2020 年 12 月以来尚未更新。
您可以尝试将chart.js降级到2.9.4吗?我认为这将解决构造函数的问题。
"chart.js": "2.9.4",
"vue-chartjs": "3.5.1",
Run Code Online (Sandbox Code Playgroud)
我创建了一个小样本,它使用您在codesandbox FYR中提供的代码。
https://codesandbox.io/s/distracted-galileo-r3lec?file=/package.json:378-401
聚苯乙烯
如果您想要更新图表库,可以查看 apex 图表 https://github.com/apexcharts/vue-apexcharts
| 归档时间: |
|
| 查看次数: |
5039 次 |
| 最近记录: |