这是一个工作多线股票图表的例子。那么只有一个小问题 - 日期以某种方式移动-1天与mysql结果相比(但现在不是重点)。
我想创建一个由表单提供的动态股票生成器。表单中有一些复选框,允许我们选择要生成的系列。
#Questions&问题 #1 PHP方面确定我们从复选框1和3中选择。我们需要做的是将它们发布到生成器文件中吗?在生成器文件中会有类似
的内容if($_POST['gen_fields'] == 1){ $return['name'] = 'Zwroty';
foreach ($result as $row) {
$date =strtotime($row['Date'])*1000;
$return['data'][] = array($date, (int)$row['totalCOunt']);
// $return[] =
}
}
嗯,我试过了,但似乎没有以某种方式工作。让我们继续讨论JS问题。
#2 JS方面: Javascript明智它也有点难以实现它必须像if语句:如果选中复选框1添加到系列。如果没有系列选择错误或添加全部3。
第二个选项我在互联网上看到了一些动态的foreach系列剧本,但似乎他们没有使用我的生成器,因为我没有$ _Get' >
<form id="form_gen" method="post" class="bootstrap-frm" style="max-width: 100% !important;">
<label>
<span>Parameters</span>
<input type="checkbox" name="gen_fields" value="1"> Zwroty
<input type="checkbox" name="gen_fields" value="2"> Doręczenia
<input type="checkbox" name="gen_fields" value="3"> W doręczeniu
</label>
<label>
<span> </span>
<input type="button" value="Generate" class="add-button" onclick="form_gen()">
</label>
</form>
JS部分
function form_gen() {
$('#form_gen').form('submit', {
url: 'api/stockchart.php',
onSubmit: function() {
},
beforeSend: function() {
},
success: function(result) {
$.getJSON('api/stockchart.php', function(json) {
// Create the chart
$('#as').highcharts('StockChart', {
rangeSelector: {
selected: 1
},
title: {
text: 'Wpisów dziennie'
},
yAxis: {
title: {
text: 'Ilość'
},
plotLines: [{}]
},
series: [{
name: 'Zwroty',
color: '#4572A7',
type: 'column',
// yAxis: 1,
data: json[1].data
}, {
name: 'Doręczenia',
color: '#45CCA7',
type: 'column',
// yAxis: 1,
data: json[2].data
}, {
name: 'W doręczeniu',
color: '#89A54E',
type: 'spline',
data: json[0].data
}]
});
});
}
});
}
PHP生成器
try {
$sth = $db->prepare("SELECT DATE(date) Date, COUNT(number) totalCOunt FROM numbers GROUP BY DATE(date)");
$sth->execute();
$result = $sth->fetchAll();
$sth = $db->prepare("SELECT DATE(rdate) Date, COUNT(number) totalCOunt FROM numbers Where `return` = 2 AND rdate != '0000-00-00 00:00:00' GROUP BY DATE(rdate)");
$sth->execute();
$returna = $sth->fetchAll();
$sth = $db->prepare("SELECT DATE(rdate) Date, COUNT(number) totalCOunt FROM numbers Where `return` = 1 AND rdate != '0000-00-00 00:00:00' GROUP BY DATE(rdate)");
$sth->execute();
$returnb = $sth->fetchAll();
/* Fetch all of the remaining rows in the result set */
// print("Fetch all of the remaining rows in the result set:\n");
}
catch(PDOException $ex){ die("Failed to run query: " . $ex->getMessage());}
try{
$return['name'] = 'Zwroty';
foreach ($result as $row) {
$date =strtotime($row['Date'])*1000;
$return['data'][] = array($date, (int)$row['totalCOunt']);
// $return[] =
}
}
catch(PDOException $ex){ die("Failed to run query: " . $ex->getMessage());}
try{
$return1['name'] = 'W doręczeniu';
foreach ($returna as $row1) {
$date1 =strtotime($row1['Date'])*1000;
$return1['data'][] = array($date1, (int)$row1['totalCOunt']);
// $return[] =
}
}
catch(PDOException $ex){ die("Failed to run query: " . $ex->getMessage());}
try{
$return2['name'] = 'Doręczony';
foreach ($returnb as $row2) {
$date2 =strtotime($row2['Date'])*1000;
$return2['data'][] = array($date2, (int)$row2['totalCOunt']);
// $return[] =
}
}
catch(PDOException $ex){ die("Failed to run query: " . $ex->getMessage());}
$result = array();
array_push($result,$return);
array_push($result,$return1);
array_push($result,$return2);
echo json_encode($result,true);