我正在製作一個時間線圖,並且我對數據有問題我需要查詢結果到數據庫沒有導致雙引號(「)。他們留下了我如何獲取結果Highcharts和JSON問題
[{「name」:「Tv Cable」,「data」:[「[1370925000000,100]」]},{「name」:「Tv Satelital」,「data」 1365654600000,100] 「 」[1368505800000,200]「, 」[1370320200000,1500]「, 」[1370925000000,500]「, 」[1370925000000,560]「, 」[1370925000000,50]「,」[13709.25億, 500]「,」[1370925000000,800]「,」[1370925000000,500]「,」[1373776200000,1000]「]},{」name「:」Tv Internet「,」data「:[」[1371097800000,500 ]「]},{」name「:」Tv Telefonia「}]
我需要它如下
[{ 「名稱」: 「電視電纜」, 「數據」:[[1370925000000,100]]},{ 「名稱」: 「電視Satelital」, 「數據」: [[1365654600000,100],[1368505800000,200],[1370320200000,1500],[1370925000000,500],[1370925000000,560],[1370925000000,50],[1370925000000,500],[1370925000000,800],[ 1370925000000,500],[1373776200000,1000]]},{「name」:「Tv Internet」,「data」:[[1371097800000,500]]},{「name」:「Tv Telefonia」}]
我一直試圖解決它,我沒有設法做到?
我讓我的圖形碼,看我做什麼
sql.php
<?php
$fecha = date("d-m-Y"); // fecha actual
$ano = date("Y"); // A単o actual
$mes = date("m"); // Mes actual
$dia = date("d"); // Dia actual
$mes_inicio= $mes-2;
$con = mysql_connect("localhost","xyolcarx_inter","xYolcar19572059");
if (!$con) {
die('Could not connect: ' . mysql_error());
}
mysql_select_db("xyolcarx_inter", $con);
$rows = array();
for ($i=1;$i<=4;$i++){
$sth = mysql_query("SELECT monto,(unix_timestamp(fecha)*1000) FROM ventas WHERE codigo_ser = '".$i."' ORDER BY fecha ASC ");
$sth2 = mysql_query("SELECT * FROM servicio WHERE codigo_ser= '".$i."'");
while($r2 = mysql_fetch_array($sth2)) {
$rows[$i]['name'] = $r2['servicio'];
}
while($r = mysql_fetch_array($sth)) {
$rows[$i]['data'][] = '['.$r['(unix_timestamp(fecha)*1000)'].','.$r['monto'].']';
}
}
$result = array();
for ($i=1;$i<=4;$i++){
array_push($result,$rows[$i]);
}
print json_encode($result, JSON_NUMERIC_CHECK);
mysql_close($con);
?>
的index.php
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<title> - jsFiddle demo</title>
<script type='text/javascript' src='https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js'></script>
<link rel="stylesheet" type="text/css" href="/css/result-light.css">
<style type='text/css'>
</style>
<script type='text/javascript'>//<![CDATA[
$(function() {
$.getJSON('sql.php', function(data) {
// Create the chart
window.chart = new Highcharts.StockChart({
chart : {
renderTo : 'container'
},
rangeSelector : {
selected : 1
},
title : {
text : 'AAPL Stock Price'
},
series : data
});
});
});
//]]>
</script>
</head>
<body>
<script src="http://code.highcharts.com/stock/highstock.js"></script>
<script src="http://code.highcharts.com/stock/modules/exporting.js"></script>
<div id="container" style="height: 500px; min-width: 500px"></div>
</body>
</html>