[Chartjs]-Put array in chart data

1👍

Use computed properties instead of data property :

export default {
  components: {
    ChanceChart
  },

  computed: {
    chartData(){
        return {
          datasets: [
            {
              label: "Enemy's Chance",
              borderColor: '#1161ed',
              data: this.myFirstArray // <- here
            },
            {
              label: 'My Chance',
              borderColor: '#f87979',
              color: '#fff',
              data: this.mySecondArray // <- here
            }
          ],
          labels: this.ennemyCards.map((x, index) => index + 1) // here you can calculate your labels
        },
        chartOptions: {
          responsive: true
        }
      }
  }

  data() {
    return {
      enemysCards : [1610, 169, 168, 167, 330, 329, 328, 327, 326, 325, 324, 323, 1, 1610, 1600, 169, 168, 167, 1610, 1600, 169, 168, 167, 11],
      myFirstArray: [40, 20, 12, 39, 10, 40, 39, 80, 40, 20, 12, 41, 190],
      mySecondArray: [40, 20, 12, 39, 10, 40, 39, 80, 40, 20, 12, 41, 190],
    }
  }

Leave a comment