douyujun0152 2018-11-23 07:02
浏览 56

数据库中的数据到laravel中的fusioncharts

I want to display the data from the database to myFusionCharts in laravel but somehow I got stuck. I can't find any answers from the documentations since they use predefined dataset in their sample.

Any help would be much appreciated.

This is my controller:

 public function index()
{
    $subj = DB::Table('tbl_subjects')               
            ->select('subject')
            ->get();
            // ->toArray()

    foreach ( $subj as $s){
        // $c = $s->subject;
        $c[] = DB::table('tbl_ordinances')
            ->where('subject', 'like', '%'.$s->subject.'%')
            ->get()
            ->count();

    }     
        // dd($subj,$c);
    return view('statistics',compact('subj','c'));
}

I " dd($subj,$c); " and it returns this values:

Collection {#302 ▼
#items: array:9 [▼
0 => {#309 ▼
  +"subject": "Peace & Order and Public Safety"
}
1 => {#311 ▼
  +"subject": "Infrastructure"
}
2 => {#312 ▼
  +"subject": "Livelihood/ Poverty Reduction"
}
3 => {#313 ▼
  +"subject": "Finance/ Investment"
}
4 => {#314 ▼
  +"subject": "Administrative Development"
}
5 => {#315 ▼
  +"subject": "Agricultural Development"
}
6 => {#316 ▼
  +"subject": "Social Services"
}
7 => {#317 ▼
  +"subject": "Environment and Disaster Management"
}
8 => {#318 ▼
  +"subject": "Tourism"
}
]
}
array:9 [▼
0 => 2
1 => 0
2 => 0
3 => 0
4 => 4
5 => 0
6 => 3
7 => 6
8 => 1
]

This is my blade:

<script type="text/javascript">
FusionCharts.ready(function() {
    var revenueChart = new FusionCharts({
type: 'pie2d',
renderAt: 'chart-container',
width: '500',
height: '500',
dataFormat: 'json',
dataSource: {
  "chart": {
    "caption": "Municipal Ordinances by subject categories",
    // "subCaption": "Last year",
    "numberPrefix": null,
    "showPercentInTooltip": "1",
    "decimals": "1",        
    "theme": "fusion",
  },
  "data": [  // I want THOSE VALUES HERE... but I don't know how..
    {"label": "h","value": "25" },   
    {"label": "h2","value": "25"},    
    {"label": "h3","value": "55"},  
  ]

}
}).render();
});
</script>

<div id="chart-container">FusionCharts will render here..</div>
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥100 连续两帧图像高速减法
    • ¥15 组策略中的计算机配置策略无法下发
    • ¥15 如何绘制动力学系统的相图
    • ¥15 对接wps接口实现获取元数据
    • ¥20 给自己本科IT专业毕业的妹m找个实习工作
    • ¥15 用友U8:向一个无法连接的网络尝试了一个套接字操作,如何解决?
    • ¥30 我的代码按理说完成了模型的搭建、训练、验证测试等工作(标签-网络|关键词-变化检测)
    • ¥50 mac mini外接显示器 画质字体模糊
    • ¥15 TLS1.2协议通信解密
    • ¥40 图书信息管理系统程序编写