I am using Vue.js with Chart.js in order to retrieve some data from Firebase and display it on a chart. This is my code:
import {Line} from 'vue-chartjs'
let Firebase = require('firebase');
//
let config = {
apiKey: '****************************',
authDomain: '****************************',
databaseURL: '****************************',
storageBucket: '****************************'
};
let firebaseApp = Firebase.initializeApp(config);
let db = firebaseApp.database();
let schools = db.ref('schools');
export default Line.extend({
firebase: {
schoolsArray: schools
},
data(){
alert('data');
return {
names: []
}
},
computed: {
schoolNames: function () {
for (let item of this.schoolsArray) {
this.names.push(item.name);
}
alert('computed');
return this.names
}
},
mounted () {
alert('mounted');
this.renderChart({
labels: this.names.toString(),
datasets: [{
label: 'School Reports', backgroundColor: '#dd4935',
data: [10, 20, 50, 12, 34, 43, 45]
}]
}, {responsive: true, maintainAspectRatio: true})
}
})
The problem is that the names array are always empty and the labels are not displayed. Here is how it looks:

I need to display the school names on the x axis!
