1

Data is available in computed properties (see screenshot), but won't render out into the PieChart control..

Anyone got any idea why ?

CODE :

<script>
import { Pie } from 'vue-chartjs'
import * as types from '../store/mutationtypes'
import { mapGetters, mapActions } from 'vuex'

export default Pie.extend({
  mounted () {
    statOrderStatus : this.$store.dispatch('getStatisticsForOrderStatus'),
    this.renderChart({
    labels: this.orderStatusChartKeys,
      datasets: [
        {
          label: 'Ticketstatus',
          backgroundColor: '#f87979',
          data: this.orderStatusChartData
        }
      ]
    })

  },
  computed: {
    ...mapGetters(["statOrderStatus"]),
    orderStatusChartData () {
      let chartData = []
      this.statOrderStatus.forEach(function(orderStatus) {
          chartData.push(orderStatus.doc_count)
      })      
      return chartData
    },
    orderStatusChartKeys () {
      let chartKeys = []
      this.statOrderStatus.forEach(function(orderStatus) {
          chartKeys.push(orderStatus.key)
      })      
      return chartKeys
    }
  }
})
</script>

VUE info : (Chrome debug)

enter image description here

1 Answer 1

3

Try making a computed property to calculate the chart data:

Look at chart.js at https://www.webpackbin.com/bins/-KpNBtUKQ67-jSFRHtNe

datasets: [
        {
          label: 'Ticketstatus',
          backgroundColor: '#f87979',
          data: this.orderStatusChartData
        }

.

computed: {
    orderStatusChartData () {
      let chartData = []
      this.statOrderstatus.forEach(function(orderStatus) {
          chartData.push(orderStatus.doc_count)
      })      
      return chartData
    }
Sign up to request clarification or add additional context in comments.

9 Comments

thanx @daniel-d :) I have only one issue here.. I'll update the question :
Updated the question with lastest code, error message, and a screenshot of State.. Hope this is helpful for solving :)
You're trying to set the data of the pie chart to an array of string values. You need to set it to the array of number values: datasets: [ { ... data: this.orderStatusChartData }. Basically you just mixed up your orderStatusChartData and orderStatusChartKeys in your chart code.
Thanks for the response @daniel-d :) It was unfortunately the same result though.. screenshot (as linked in the question) is exactly like now : Only that red short bar on top, no chart... Any other things you might think could be missing ? PS! I have tried it with the demo-data, and it displayed correctly.. Could it be an issue with datatype ? both should be arrays? I have tried with both []'s and {}'s around with no success on that either...
I don't know Terje. The orderStatusChartData looks good in the inspector. It should be working as far as I can see.
|

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.