转换json数据做谷歌图表

时间:2016-11-06 00:10:24

标签: php json graph

所以我在 PHP 中使用cURl来访问JSON对象并从中获取数据。我收到了所有数据,但我不明白如何用这些信息绘制图表。

这是 PHP脚本:

<?php
// Generated by curl-to-PHP: http://incarnate.github.io/curl-to-php/
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, " https://xxx.xxx.pt/api/objgroupinfo/16Jcr05g37KpLklz");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET");
$headers   = array();
$headers[] = "X-Apikey: xxxxxxxxxxxxxxxxxxxxxxxx";
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
$result = curl_exec($ch);
if (curl_errno($ch)) {
    echo 'Error:' . curl_error($ch);
}
curl_close($ch);
// Generated by curl-to-PHP: http://incarnate.github.io/curl-to-php/
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, " https://xxx.xxxxx.pt/api/dataout/IAfhAfTIUZrCje5q.json");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET");
$headers   = array();
$headers[] = "X-Apikey: xxxxxxxxxxxxxxxxxxxx";
$headers[] = "X-Startdate: 2016-10-01 00:00:00";
$headers[] = "X-Enddate: 2016-10-10 15:00:00";
$headers[] = "X-Channelnum: 0";
$headers[] = "X-Reclimit: 200";
$headers[] = "User-Agent: xxxx/1.0";
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
$result = curl_exec($ch);
if (curl_errno($ch)) {
    echo 'Error:' . curl_error($ch);
}
$json = json_decode($result, true);
print_R($json);
echo "<h1> loll </h1>";
echo $json['location'];
echo "<br>";
echo $json['object_name'];
echo $json['channels'];
for ($i = 0; $i < count($json['channels']); $i++) {
    echo $json['channels'][$i];
}
curl_close($ch);
?>

我得到的是这样的东西:

enter image description here

我已经使用j son_decode将数据转换为PHP数组,但是如何使用这些数据来构建图形?

1 个答案:

答案 0 :(得分:0)

演示如下,让我知道是否有任何疑问。

您必须选择Anular JS才能更快地实施。

 <div>
 <div google-chart chart="chart" style="{{chart.cssStyle}}"/>

Demo