gpt4 book ai didi

javascript - **jqplot**图表从**数据库**获取数据作为折线图并使用**php**应用程序显示

转载 作者:行者123 更新时间:2023-11-28 00:23:32 27 4
gpt4 key购买 nike

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(*) 更改为其他内容

关于javascript - **jqplot**图表从**数据库**获取数据作为折线图并使用**php**应用程序显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29764183/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com