**jqplot** 图表 从 **数据库** 获取数据用于线图并使用 **php** 应用程序显示

**jqplot** charts Fetch the data from **database** for line graph and display using **php** application

Below is the code that i have worked on which contains the code to fetch the data from database and add it into the $orderArray1 variable . I want to know how to add these data to chart.

if(isset($_POST['submit'])=="GeneratePieChart"){

    $fromDate=$_POST['datepicker'];
    $toDate=$_POST['datepicker1'];
    $sql="SELECT count(*),DATE_FORMAT(order_date,'%d-%b-%Y') as order_date FROM customer_order WHERE order_date BETWEEN '$fromDate' AND '$toDate' GROUP BY DATE_FORMAT(order_date, '%Y%m%d') LIMIT 0 , 30";
    echo $sql."<br>";

    $result = mysql_query($sql);
    while($row=mysql_fetch_assoc($result)) {
        $resultset[] = $row;
    }
    $orderCount = count($resultset);
    $orderArray = $resultset;

    $orderArray1 = json_encode($orderArray);

}

$orderArray1的结果如下图

[{"count(*)":"29","order_date":"20-Apr-2015"},{"count(*)":"5","order_date":"21-Apr-2015"}]

Below is the code for drawing line chart

<script type="text/javascript">
$(document).ready(function(){
    var jQueryArray = <?php echo $orderArray1; ?>;
    alert(jQueryArray);
    **var line1=[['23-May-08', 578.55], ['20-Jun-08', 566.5], ['25-Jul-08', 480.88], ['22-Aug-08', 509.84],
        ['26-Sep-08', 454.13], ['24-Oct-08', 379.75], ['21-Nov-08', 303], ['26-Dec-08', 308.56],
        ['23-Jan-09', 299.14], ['20-Feb-09', 346.51], ['20-Mar-09', 325.99], ['24-Apr-09', 386.15]];**
    var plot1 = $.jqplot('chart1', [line1], {
        title:'Data Point Highlighting',
        axes:{
            xaxis:{
                renderer:$.jqplot.DateAxisRenderer,
                tickOptions:{
                    formatString:'%b&nbsp;%#d'
                }
            },
            yaxis:{
                tickOptions:{
                    formatString:'$%.2f'
                }
            }
        },
        highlighter: {
            show: true,
            sizeAdjust: 7.5
        },
        cursor: {
            show: false
        }
    });
});

I want to know how to pass the array data that i have got into the chart in place of var line1 where the first value will be date and second value will be count as i have got the result in $orderArray1

试试这个:

jQueryArray = [{"count(*)":"29","order_date":"20-Apr-2015"},{"count(*)":"5","order_date":"21-Apr-2015"}]
var line1 = [];
$.each(jQueryArray,function(index,val) {
      line1.push([val.order_date,val.count(*)]);
});

Ps:最好将索引 count(*) 更改为其他内容