javascript - Fusioncharts 使用 vue 和 laravel 显示来自控制器的数据,其中条件是计数和分组
问题描述
我有一个圆环图,我想根据该列显示用户的计数type
。在我的控制器中,我得到了一个返回计数的查询。我的问题是当我在我的 vue 组件中渲染图表时,没有显示数据。但是当我查看我的 vue devtools 时,显示的数据是数组/对象格式。有人可以知道我该怎么做吗?
我的控制器
$users = \DB::table('users')
->select(\DB::raw('count(*) as type'))
->groupBy('type')
->get();
return response()->json($users);
我在 vue 组件中的脚本
return {
users: [],
"type": "doughnut2d",
"renderAt": "chart-container",
"width": "550",
"height": "350",
"dataFormat": 'json',
"dataSource": {
"chart": {
"caption": "User Count", "theme": "fusion"
}
,
"data": [{
"label": "Admin Users",
"value": this.users
},
]
}
}
},
methods: {
getdata(){
axios.get('api/graphs')
.then(res=>{
this.users = res.data;
this.dataSource.data[0].value = this.users
})
}
},
Vue 开发工具
4
用户类型 admin和普通用户的当前计数2
是正确的。所以甜甜圈会分成两份。
解决方案
您还应该返回用户的类型,以便 dataSource.data.label 是动态的。
它应该看起来像这样。
dataSource.data.push({
'label': res.data.typeUser
'value': res.data.count
})
并在您的 dataSource.data
"dataSource": {
"chart": {
"caption": "User Count", "theme": "fusion"
}
,
"data":[]
}
请更改您的查询。它应该返回类型和计数。像这个。如何在laravel中返回响应对象json
推荐阅读
- string - 获取句子中单词的第一个字母
- python - django-tables2 自定义表格可视化
- android - 即使进行了所有优化,Android Emulator 仍然滞后
- php - 将输入添加到条带表单
- vb6 - 由于“WS.Reputation.1”,Symantec Endpoint 删除了 VB6 IDE
- swift - NetService 在调试时获得正确的 Inet 类型,但不能从存档的 IPA 工作
- regex - 匹配正则表达式:仅在空格之间提取数字
- python - 从具有定义概率的 Pandas 组内进行抽样
- javascript - 函数的 Javascript 语法,Internet Explorer <= 11 (vuejs) 中的问题
- date - Google表格将文本字符串单元格转换为日期+持续时间单元格