我知道答案会变得简单得多,然后我才能做到。我在while循环中添加了以下if语句。
<?php
echo "['Month', '$year1' , '$year2' , '$currentYear'],";
require('./PHPConnect.php');
$statement1 = @mysqli_query($dbc, $query1);
while($row = mysqli_fetch_array($statement1)){
if($row["Year3"] == NULL ? $row["Year3"] = 'null' : $row["Year3"] = $row["Year3"]);
echo "['".$row["Month"]."', ".$row["Year1"].", ".$row["Year2"].", ".$row["Year3"]."],";
}
mysqli_close($dbc);
?>
作为更新,我们现在知道问题是MySql吐出NULL并且javascript需要null。关于如何将MySql NULL int值变为小写null的任何想法。
*我想知道是否有人可以帮助我。我创建了一个折线图,用于按当月和之前的2个月按月显示公司销售情况。它工作正常,但是因为此时剩余的几个月中有0个销售额显示该行的急剧下降。我们不希望看到这一点,所以我尝试将数据库中的0更改为空值并使用interpolateNulls false。但是,当我添加interpolateNulls选项时,折线图会断开并且不再显示任何内容。有什么想法吗?
<script type="text/javascript">
var data;
var chart;
google.charts.load('current', {'packages':['corechart']});
google.charts.setOnLoadCallback(drawChart);
function drawChart(){
data = google.visualization.arrayToDataTable([
<?php
echo "['Month', '$year1' , '$year2' , '$currentYear'],";
require('./PHPConnect.php');
$statement1 = @mysqli_query($dbc, $query1);
while($row = mysqli_fetch_array($statement1)){
echo "['".$row["Month"]."', ".$row["Year1"].", ".$row["Year2"].", ".$row["Year3"]."],";
}
mysqli_close($dbc);
?>
]);
var options = {
backgroundColor: 'transparent',
title:'Total Sales By Month',
width:600,
height:500,
interpolateNulls: false,
legend: {position: 'bottom'}
};
var chart = new google.visualization.LineChart(document.getElementById('chart_div'));
chart.draw(data, options);
}