谢谢你。我现在可以看到第二张图,但我拥有的第二张图没有任何数据,所以它只是一张空白图表。这是我的 php 代码。我究竟做错了什么?我的代码:
<?php
/* Open connection to "zing_db" MySQL database. */
$mysqli = new mysqli("localhost", "root", "database123", "productno");
/* Check the connection. */
if (mysqli_connect_errno()) {
printf("Connect failed: %s\n", mysqli_connect_error());
exit();
}
?>
<script>
/* First line chart */
var myData=[<?php
$data=mysqli_query($mysqli,"SELECT * FROM records");
while($info=mysqli_fetch_array($data))
echo '["'.$info['Date'].'",'.$info['Alibaba'].'],'; /* Data is formatted here, using the . concatenation operator */
echo '[]'; /* We'll end up with a trailing comma, so we add an empty element here to pop off later*/
?>];
//--------- Second Line Chart ---------------
var myData1=[<?php
$data1=mysqli_query($mysqli,"SELECT * FROM records");
while($info1=mysqli_fetch_array($data1))
echo '["'.$info1['Date'].'",'.$info1['Lelong'].'],'; /* Data is formatted here, using the . concatenation operator */
echo '[]'; /* We'll end up with a trailing comma, so we add an empty element here to pop off later*/
?>];
<?php
/* Close the connection */
$mysqli->close();
?>
myData.pop(); /* Pop off the final, empty element from the myData array */
//Display first line chart
window.onload=function(){
zingchart.render({
id:"AlibabaChart",
width:"100%",
height:300,
data:{
"type":"line",
"title":{
"text":"Alibaba"
},
"series":[
{
"values":myData
}
]
}
});
//Display second line chart
zingchart.render({
id:"LelongChart",
width:"100%",
height:300,
data:{
"type":"line",
"title":{
"text":"Lelong"
},
"series":[
{
"values":myData1
}
]
}
});
};
</script>
仅供参考,数据来自同一个表,x 值和数据库,但不同的列(y 值)。谢谢!