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.

1
  • Have you tried Props Commented Feb 5, 2019 at 9:20

2 Answers 2

2

You should not use one variable in another directly in data. series: [this.test, 5, 4], This will return null in this.test. You can set series empty intially and set values later. series:[] And then populate series in some function. Or else use computed() as follows:

computed: {
    series() {
        return this.test;
    }
}
Sign up to request clarification or add additional context in comments.

1 Comment

This is not work. Seems causes series:[] "apexcharts.min.js?3d1e:6 Uncaught (in promise) TypeError: Cannot read property 'data' of undefined"
1

You can update the chart data dynamically like this.

this.chartOptions = {labels:['dynamic data here']}
this.series = ['dynamic data here']

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.