我的line-chart
. 来自 api/controller 的数据无法在我的图表上传输,但作为响应显示了我的所有数据
如图所示, 里面line-chart
是空的,但是response
里面有一个数据。
我有一个错误是说
TypeError:无法读取 app.js:86744 处未定义的属性“地图”
我不知道如何解决它请帮助我。谢谢
代码
报告.Vue
<div class="container">
<h1>USAGE</h1>
<mortalityLineChart :chartdata="datacollection"> </mortalityLineChart>
</div>
</template>
<script>
export default {
data () {
return {
date_input: null,
number_of_morality: null,
chicken_age:null,
datacollection: null
}
},
created () {
this.fillData()
},
mounted () {
this.fillData()
},
methods: {
fillData () {
axios.get('/api/report')
.then(response =>{
let results = response.data.data
let dateresult = results.map(a => a.date_input)
let mortalityresult = results.map(a => a.number_of_morality)
let chickenageresult = results.map(a => a.chicken_age)
this.date_input = dateresult
this.number_of_morality= mortalityresult
this.chicken_age= chickenageresult
this.datacollection = {
labels: this.number_of_morality,
datasets:[
{
label:'Mortality',
backgroundColor: '#f87979',
data:this.date_input
}
]
}
})
.catch(error => {
console.log(error)
})
},
}
}
</script>
报告MortalityLineChart.js
import {Line} from 'vue-chartjs' // We specify what type of chart we want from vue-chartjs and the mixins module
export default({
extends: Line, //We are extending the base chart class as mentioned above
props: ["mychartData"],
watch: {
mychartData: {
handler: function (val) {
this._chart.update()
},
deep: true
}
},
data () {
return {
options: { //Chart.js options
scales: {
yAxes: [{
ticks: {
beginAtZero: true
},
gridLines: {
display: true
}
}],
xAxes: [ {
gridLines: {
display: false
}
}]
},
legend: {
display: true
},
responsive: true,
maintainAspectRatio: false
}
}
},
mounted () {
// this.chartData is created in the mixin
this.renderChart(this.chartData, this.options)
}
})
应用程序.js
import reportMortalityLineChart from './charts/reportMortalityLineChart'
Vue.component('mortalityLineChart',reportMortalityLineChart);
预习
2017-12-10: 4
2017-12-11: 12
2017-12-12: 17
2017-12-13: 16
2017-12-14: 17
2017-12-15: 10
2017-12-16: 11
2017-12-17: 13
2017-12-18: 6
2017-12-19: 1
2017-12-20: 13
2017-12-21: 16
2017-12-22: 4
2017-12-23: 10
2017-12-24: 10
2017-12-25: 10
2017-12-26: 19
2017-12-27: 5
2017-12-28: 7
2017-12-29: 13
2017-12-30: 13
2017-12-31: 10
2018-01-01: 13
2018-01-02: 23
2018-01-03: 15
2018-01-04: 35
2018-01-05: 61
报告控制器.php
public function index()
{
$mortality = Mortality::where('cycle_id', 2)
->where(['user_id' => Auth::id()])
->pluck('number_of_mortality','date_input','chicken_age');
return response()->json($mortality);
}
死亡率表
Schema::create('mortalities', function (Blueprint $table) {
$table->increments('id');
$table->date('date_input');
$table->integer('number_of_mortality');
$table->integer('chicken_age');
$table->mediumText('cause_of_death')->nullable();
$table->unsignedInteger('cycle_id');
$table->unsignedInteger('user_id');
$table->timestamps();