1

I am buiding a website with laravel and using the vuejs to manage the front-end. I want to display several charts through vue-chartjs but the vue-chartjs is not showing the graph even though the data is successfully passed. I have been following their website guide but the graph never displays. enter image description here My Vue Component

<teplate>
    <div>
      ...
    <line-chart :chart-data="datacollection"></line-chart>
    <button @click="fillData()">Randomize</button>
    </div>
</template>

<script>
import Table from '../equipments/table.vue'
import LineChart from '../equipments/LineChart.js'
import DropDownList from '../equipments/dropdownlist.vue'
    export default {
    data () {
      return {
        datacollection: null
      }
    },
        components: {
            LineChart,
            Table,
            DropDownList
        },
    mounted () {
      this.fillData()
    },
    methods: {
      fillData () {
        this.datacollection = {
          labels: ['weqw','wewq'],
          datasets: [
            {
              label: 'Data One',
              backgroundColor: '#f87979',
              data: [this.getRandomInt(), this.getRandomInt()]
            }, 
            {
              label: 'Data One',
              backgroundColor: '#f87979',
              data: [this.getRandomInt(), this.getRandomInt()]
            }
          ]
        }
      },
      getRandomInt () {
        return Math.floor(Math.random() * (50 - 5 + 1)) + 5
      }
    }
  }
</script>

<style>
  .small {
    max-width: 600px;
    margin:  150px auto;
  }
</style>

my Chart.js

import { Line, mixins } from 'vue-chartjs'
const { reactiveProp } = mixins

export default {
  extends: Line,
  mixins: [reactiveProp],
  props: ['options'],
  mounted () {
    // this.chartData is created in the mixin.
    // If you want to pass options please create a local options object
    this.renderChart(this.chartData, this.options)
  }
}

Hope could receive some hints here, thanks in advance

3
  • What version of chart.js are you using? Commented Sep 5, 2021 at 17:11
  • "dependencies": { "@popperjs/core": "^2.10.1", "bootstrap": "^4.5.3", "bootstrap-vue": "^2.21.2", "chart.js": "^3.5.1", "vue": "^2.6.14", "vue-chartjs": "^3.5.1", "vue-router": "^3.5.2", "vue-sidebar-menu": "^5.0.1" } @LeeLenalee Commented Sep 5, 2021 at 17:26
  • these are all my dependency installed from npm. both chart.js and vue-chartjs version are 3.5.1 Commented Sep 5, 2021 at 17:26

1 Answer 1

2

Vue-chartjs only works with v2 of chart.js. So you will need to downgrade chart.js to version 2.9.4 if you want to use it.

npm i [email protected]

Sign up to request clarification or add additional context in comments.

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.