我应该写一系列的高级图表

时间:2014-11-11 07:37:49

标签: php mysql highcharts

我想将我的数据库数据串联起来 我的表“暴徒”是这样的: ![我的桌子名为" mob"] [1]

Icost数据不真实 我的代码是这样的:

<?php
include '../../class/jdf.php';
require_once "../../db.php";
$db = new db();
$query_time = "SELECT DISTINCT iDate FROM mob WHERE 1 ";
$datashow = $db->get_arr($query_time);

$time = array();
foreach ($datashow as $key => $row) {
    $format = ' Y/m/d ';
    $time[] = jdate($format, $row['iDate']);

}
$query_cost = "SELECT * FROM mob WHERE 1 ";
$data = $db->get_arr($query_cost);                   
   $datamin = $db->get_field('mob','MIN(iCost)','1');
   $datamin = $datamin -100;
   $datamax = $db->get_field('mob','MAX(iCost)','1'); 



<!DOCTYPE HTML>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
        <title>Highcharts Example</title>

        <script src="../../js/jquery-1.9.1.min.js"></script>
        <script src="../../js/highcharts.js"></script>
        <style type="text/css">
        </style>
        <script type="text/javascript">

           Highcharts.setOptions({

                lang: {
                    numericSymbols: null
                },
            });
            $(function() {
                $('#container').highcharts({

                    chart:
                            {
                        type: 'column'
                    },
                    title: {
                        text: 'my chart '
                    },
                    subtitle: {
                        text: 'mob'
                    },
                    xAxis: {
                        categories: [

                            <?php
                            foreach ($time as $value) {
                                echo "'" . $value . "',";
                            }
                            ?>

                        ]
                    },
                    yAxis: {
                        min :<?php echo $datamin ?>,
                        max :<?php echo $datamax ?>,
                        title: {
                            text: 'cost'
                        }
                    },
                    tooltip: {
                        headerFormat: '<span style="font-size:10px">{point.key}</span><table>',
                        pointFormat: '<tr><td style="color:{series.color};padding:0">{series.name}: </td>' +
                                '<td style="padding:0"><b>{point.y:.1f} mm</b></td></tr>',
                        footerFormat: '</table>',
                        shared: true,
                        useHTML: true
                    },
                    plotOptions: {
                        column: {
                            pointPadding: 0.2,
                            borderWidth: 0
                        }
                    },
                    series: []
                });
            });
        </script>
    </head>
    <body>

        <script src="../../js/modules/exporting.js"></script>

        <div id="container" style="min-width: 310px; height: 400px; margin: 0 auto"></div>

    </body>
</html>

我应该连续写什么来制作像这样的图表

![我的图表样本就是这样] [2]

// [1]:http://i.stack.imgur.com/WBJm5.jpg // [2]:http://i.stack.imgur.com/DYZjm.jpg

请帮帮我。 谢谢

1 个答案:

答案 0 :(得分:0)

在你的php中,准备正确的数组(根据avascript结构)并使用json_encode()。在javasctrip中调用$ .getJSON(),获取数据并在highcharts中使用。

有关预处理数据的更多信息,here