2

I am trying to use dynamic data in my donut apexchart, but I don't know the correct way to do it.

I tried setting "test: 5" under data and then change the static number in series: [this.test, 4, 1]. Did not output anything, I am new to programming.

<script>
import VueApexCharts from 'vue-apexcharts'
export default {
name: 'Dashboard',
components: {
apexcharts: VueApexCharts
},
data () {
return {
  test: 6,
  series: [this.test, 5, 4],
  chartOptions: {
    plotOptions: {
      pie: {
        donut: {
          labels: {
            show: true,
            name: {
              fontSize: '24px'
            },
            value: {
              fontSize: '34px',
              color: '#fff'
            }
          }
        }
      }
    },
    tooltip: {
      enabled: false
    },
    legend: {
      show: false
    },
    fill: {
      colors: ['#4b367c', '#2aa5ed', '#db2828']
    },
    dataLabels: {
      enabled: false
    },
    labels: ['Utkast', 'Öppen', 'Förfallen'],
    colors: ['#4b367c', '#2aa5ed', '#db2828']
  }
}
},
mounted () {
this.$store.commit('setPageTitle', { title: 'Översikt' })
}
}
</script>

My goal is to reach in to firebase and use the data from there, but to start with I just wanted to test out how to add any data and failed here already.

4

2 回答 2

1

您不应该直接在数据中使用另一个变量。系列:[this.test, 5, 4],这将在 this.test 中返回 null。您可以先将系列设置为空,然后再设置值。series:[] 然后在某个函数中填充系列。或者使用 computed() 如下:

computed: {
    series() {
        return this.test;
    }
}
于 2019-02-05T09:25:56.973 回答
1

您可以像这样动态更新图表数据。

this.chartOptions = {labels:['dynamic data here']}
this.series = ['dynamic data here']
于 2021-02-19T04:46:55.170 回答