douping1581 2016-11-02 03:44
浏览 67

使用dataloader将php / mysql数据加载到amcharts

I am new to AmCharts and having trouble to display the simple graph that I needed. I have used codes from the AmCharts live editor. This is the PHP file (getGred.php)

   $query = "SELECT gred, COUNT( gred ) AS bilangan FROM borg_peribadi GROUP BY gred";
$result = mysql_query( $query );
//echo $query;
//echo "<br>";
$rows = array();
while ($data = mysql_fetch_assoc ($result)){
     $rows[] = array(
    "gred" => $data[ 'gred' ],
    "bilangan" => $data[ 'bilangan' ]
  );
  }

  echo json_encode( $rows );

And this is what I got from AmCharts tutorial:

<!DOCTYPE html>
<html>
    <head>
        <title>Laporan eOrientasi</title>
        <meta name="description" content="chart created using amCharts live editor" />

        <!-- amCharts javascript sources -->
        <script src="../amcharts/amcharts.js" type="text/javascript"></script>
        <script src="../amcharts/serial.js" type="text/javascript"></script>

        <!-- amCharts plugins -->
        <script src="https://www.amcharts.com/lib/3/plugins/export/export.min.js type="text/javascript""></script>
        <link rel="stylesheet" href="https://www.amcharts.com/lib/3/plugins/export/export.css">
        <script src="../amcharts/plugins/dataloader/dataloader.min.js" type="text/javascript"></script>

        <!-- amCharts javascript code -->
        <script type="text/javascript">
            AmCharts.makeChart("chartdiv",
                {
                    "type": "serial",
                    "dataLoader": {
                        "url": "getGred.php",
                        "format": "json"
                    },
                    "categoryField": "gred",
                    "angle": 30,
                    "depth3D": 30,
                    "startDuration": 1,
                    "export": {
                        "enabled": true
                    },
                    "categoryAxis": {
                        "gridPosition": "start"
                    },
                    "chartCursor": {
                        "enabled": true
                    },
                    "chartScrollbar": {
                        "enabled": true
                    },
                    "trendLines": [],
                    "graphs": [
                        {
                            "balloonText": "[[title]] of [[category]]:[[value]]",
                            "fillAlphas": 1,
                            "id": "AmGraph-1",
                            "title": "bil. pegawai",
                            "type": "column",
                            "valueField": "bilangan"
                        }
                    ],
                    "guides": [],
                    "valueAxes": [
                        {
                            "id": "ValueAxis-1",
                            "title": "Bilangan"
                        }
                    ],
                    "allLabels": [],
                    "balloon": {},
                    "legend": {
                        "enabled": true,
                        "useGraphSettings": true
                    },
                    "titles": [
                        {
                            "id": "Title-1",
                            "size": 15,
                            "text": "BIL PEGAWAI MELAPOR DIRI MENGIKUT GRED"
                        }
                    ],
                //  "dataProvider":  AmCharts.loadJSON('laporan/getGred.php')

                }
            );
        </script>
    </head>
    <body>
        <div id="chartdiv" style="width: 100%; height: 400px; background-color: #FFFFFF;" ></div>
    </body>
</html>

The problem is not the graph is not showing, only displays below:output

Hope to get some pointers on any of errors or mistakes. Thank you.

edit: i've added the output from getGred.php

[{"gred":"29","bilangan":"1"},{"gred":"41","bilangan":"5"},{"gred":"44","bilangan":"6"}]

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 基于卷积神经网络的声纹识别
    • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
    • ¥100 为什么这个恒流源电路不能恒流?
    • ¥15 有偿求跨组件数据流路径图
    • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
    • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
    • ¥15 CSAPPattacklab
    • ¥15 一直显示正在等待HID—ISP
    • ¥15 Python turtle 画图
    • ¥15 stm32开发clion时遇到的编译问题