P粉3389695672023-08-31 18:14:05
您沒有將資料設定為回應。請使用計算
這段程式碼可以解決問題:
<script setup> import { storeToRefs } from 'pinia' import { useStore} from '@/store/pinia-store-file'; import { Chart as ChartJS, CategoryScale, LinearScale, PointElement, LineElement, Title, Tooltip, Legend } from 'chart.js'; import { Line } from 'vue-chartjs'; import { computed } from "vue" ChartJS.register( CategoryScale, LinearScale, PointElement, LineElement, Title, Tooltip, Legend ); const store = useStore(); const storeData= storeToRefs(store); const data = computed(() => ({ labels: [...Array(storeData.arr.value.length).keys()], datasets: [ { label: 'Data One', backgroundColor: '#f87979', data: storeData.arr.value } ] })) const options = { responsive: true, maintainAspectRatio: false } </script> <template> <Line :data="data" :options="options" /> </template>