A
A
asferot2019-02-12 10:36:57
Vue.js
asferot, 2019-02-12 10:36:57

How to pass data to chart?

I'm using the vue-chartkick charting library. There was a problem. I need to transfer my parameter from the database to the chart, in the name field, so that the names are displayed. the data transfer there consists of name - the name of the field and date - the value of this field. That is :data="[{name: "manager", data: 53}]" . I need to pass names of managers to name. I get them through vuex.

filterManagChart () {
    return this.$store.getters.filterManagersChart
}

If you do this, then the following comes up::data="[{name:filterManagChart, data: 53}]"
data:Array[1]
 0:Object
   data:53
    name:Array[11]

And you need
data:Array[11]
 0:Object
   data:53
   name:Array[1]
     0: "Залупкин"

1:Object
   data:53
   name:Array[1]
      1: "Пупкин"

That is, split the incoming array of managers. How can I do that?
It is possible to do this:
:data="[{name:filterManagChart[0], data: 53}, {name:filterManagChart[1], data: 53}]"
but it's not very pretty.
I hope that I explained more or less clearly, if you need to throw something off, ask.
Chart Library Documentation

Answer the question

In order to leave comments, you need to log in

1 answer(s)
0
0xD34F, 2019-02-12
@asferot

:data="chartData"

computed: {
  chartData() {
    return this.$store.getters.filterManagersChart.map(n => ({
      name: n,
      data: 53,
    }));
  },
},

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question