2
,以便检索来自火力地堡一些数据,并在图表上显示它,我使用Vue.js与chart.js之数组。 这是我的代码:动态填充与火力地堡数据Vue.js
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})
}
})
我需要在x轴上显示学校名称!下面
我已经发布了一个更多的图片,显示了名称检索但在图上没有显示! –
如果你再次在'.once'回调中调用'renderChart'方法有帮助吗? – user2520818
是的我使用这段代码进入方法生命周期钩子并在renderChart之前调用它,但仍然看不到任何标签o我的图表 –