jquery - 如何在 laravel 的 jquery 中调用 ajax
问题描述
我想在dynamic chart
jQuery 的帮助下创建一个。我想在图表中传递label
这value
两个数组。我怎样才能做到这一点?
这是控制器功能:
public function chart()
{
$govtRecievablesStatus = DB::select("select LABEL,round(sum(value)/1000000,1) value from (
select null as link,LABEL,value from (
select * from (
select case when 'ALL'='ALL' then 'ALL' else COMPANY end as link, LABEL,sum(VALUE) value from(
select * from APEX_BI_GOVT_RCV_V)
group by case when 'ALL'='ALL' then 'ALL' else COMPANY end,LABEL
)
where link='ALL')
union all
select * from (
select null as link,'Not Yet due for Filing' label,round(SUM(REBATE_AMOUNT)) value
from xx_rebate_refund
where org_id = 10
and status = 'NOT_REALIZE')
where 'AL
L' in ('USD','ALL'))
group by LABEL");
$label=[];
foreach($govtRecievablesStatus as $gs){
$label[] = $gs->label;
}
// return $label;
$value= [];
foreach($govtRecievablesStatus as $gs){
$value[] = $gs->value;
}
// return $value;
$data = array(
'label' => $label,
'value' => $value
);
// return $data;
return view('governmentreceivables::dashboard')->with($data);
}
这是jQuery代码:
$(document).ready(function() {
// console.log("Hello")
var e = {
chart: {
width: "100%",
type: "pie"
},
ajax: function() {
var urlPath = 'http://' + window.location.hostname + '/dashboard';
var request = $.ajax({
method: 'GET',
url: urlPath,
});
request.done(function(response) {
console.log(response);
})
},
// obj =
// o.labels ;
// o.values
labels: labels,
value: value,
// series:[44,55,13,43,22],
legend: {
position: "bottom"
},
responsive: [{
breakpoint: 480,
options: {
chart: {
width: 300
},
legend: {
position: "bottom",
offsetY: 40
}
}
}]
};
(t = new ApexCharts(document.querySelector("#simplePie"), e)).render()
});
请帮忙谢谢。
解决方案
推荐阅读
- python - python threading - 多参数和返回
- python - 反斜杠和括号如何在 re.findall() 中工作?
- python - 将字典值输出到文本文件:解耦列表和字符串
- r - 使用“mi”包时,我在 r 中不断收到“必须是矢量”错误
- facebook-graph-api - Facebook 广告 - 创建广告创意时出错
- python - python 装饰器如何更改装饰函数中的调用?
- android - RecyclerView 滑动操作而不删除
- c# - 在基类中初始化 ApplicationContext
- c# - C#反序列化自动将字符串反序列化为字节数组以通过自定义代码进行属性?
- javascript - 基于 Three.js 中的新枢轴动画旋转对象