首页 > 解决方案 > How do I add dynamic data to apexcharts using vue.js?

问题描述

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.

标签: vue.jsapexcharts

解决方案


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

computed: {
    series() {
        return this.test;
    }
}

推荐阅读