【发布时间】:2018-05-21 11:38:51
【问题描述】:
全部。
我想从我的 JSON 数据构建图表,但不明白怎么做。 数据获取('receive'),并建立表。没关系
var ordersTable = Vue.component('orders-table', {
template: `
<div>
<table class="table table-bordered">
<thead>
<tr>
<th>orderdate</th>
<th>cancelled</th>
<th>reserved</th>
<th>delivered</th>
<th>ordersumm</th>
</tr>
</thead>
<tbody>
<tr v-for="column in orders">
<td>{{column.orderdate}}</td>
<td>{{column.cancelled}}</td>
<td>{{column.reserved}}</td>
<td>{{column.delivered}}</td>
<td>{{column.ordersumm}}</td>
</tr>
</tbody>
</table>
</div>
`,
data: function () {
return {
orders: []
}
},
created:function() {
fetch('/receive/')
.then(res => res.json())
.then(res => {
this.orders = res;
});
},
});
我尝试使用 orderdate 标签和 3 个数据集构建图表:已取消、已保留、已交付。 像这样: enter image description here 我该怎么做?标签和数据必须从 fetch 中填充。我不工作的代码:
var orderChart = Vue.component('order-chart', {
extends: VueChartJs.Bar,
mounted () {
this.renderChart({
labels: [],
datasets: [
{
label: 'cancelled',
backgroundColor: 'red',
data: []
},
{
label: 'reserved',
backgroundColor: 'blue',
data: []
},
{
label: 'delivered',
backgroundColor: 'green',
data: []
}
]
}, {responsive: true, maintainAspectRatio: false})}
,
data: function () {
return {
orders: []
}
},
created:function() {
fetch('/receive/')
.then(res => res.json())
.then(res => {
this.orders = res;
});
},
})
【问题讨论】:
标签: javascript web vue.js chart.js frontend