我正在制作时间线图,但我需要的数据有问题 对数据库的查询结果没有导致双引号 (")。他们留下了我如何获得结果的示例
[{"name":"Tv Cable","data":["[1370925000000,100]"]},{"name":"Tv Satelital","data":["[1365654600000,100]"," [1368505800000,200]","[1370320200000,1500]","[1370925000000,500]","[1370925000000,560]","[1370925000000,50]","[1370925000700,500000]2"[ ,800]","[1370925000000,500]","[1373776200000,1000]"]},{"名称":"电视互联网","数据":["[1371097800000,500]"]},{" name":"Tv Telefonia"}]
我需要它跟随
[{“名称”:“电视电缆”,“数据”:[[1370925000000,100]]},{“名称”:“电视卫星”,“数据”:[[1365654600000,100],[1368505800000,200] ,[1370320200000,1500],[1370925000000,500],[1370925000000,560],[1370925000000,50],[137092500000000,500] ,{"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);
?>
索引.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>