У меня проблема с линейной диаграммой, которая отображает ошибку «Все серии на заданной оси должны быть одного типа данных», когда запрос дает нулевой результат или нет строк.
Если вы посмотритетщательно 7 запросов (каждый рисует линию на одном и том же графике), если какой-либо запрос возвращает пустой результат (без строк), я получаю ошибку в заголовке темы.Когда все запросы не пусты, диаграмма корректно работает.
Есть ли способ избежать этой ошибки?
<?php
$curyear = date('Y');
$con = mysqli_connect('xxx','xxx','xxx','xxx');
?>
<html>
<head>
<!--Load the AJAX API-->
<script type="text/javascript" src="https://www.google.com/jsapi">
</script>
<script type="text/javascript">
// Load the Visualization API and the piechart package.
google.load('visualization', '1.0', {'packages':['corechart']});
// Set a callback to run when the Google Visualization API is loaded.
google.setOnLoadCallback(drawChart);
// Callback that creates and populates a data table,
// instantiates the pie chart, passes in the data and
// draws it.
function drawChart() {
var data1 = google.visualization.arrayToDataTable([
['Date', 'LaMotta'],
<?php
$query = "SELECT responsabile, sum(val_fattu) as LaMotta, data_dichiarato FROM dichiarati_myennova WHERE responsabile = 'ADMRZ01' and dichiarati_myennova.DATA_DICHIARATO > (NOW() - INTERVAL 270 DAY) GROUP BY MONTH(data_dichiarato), responsabile ORDER BY data_dichiarato";
$exec = mysqli_query($con,$query);
while($row = mysqli_fetch_array($exec)){
echo "['".date("Y/m", strtotime($row['data_dichiarato']))."',".$row['LaMotta']."],";
}
?>
]);
var data2 = google.visualization.arrayToDataTable([
['Date', 'Spadone'],
<?php
$query = "SELECT responsabile, sum(val_fattu) as Spadone, data_dichiarato FROM dichiarati_myennova WHERE responsabile = 'ADMRZ02' and dichiarati_myennova.DATA_DICHIARATO > (NOW() - INTERVAL 270 DAY) GROUP BY MONTH(data_dichiarato), responsabile ORDER BY data_dichiarato";
$exec = mysqli_query($con,$query);
while($row = mysqli_fetch_array($exec)){
echo "['".date("Y/m", strtotime($row['data_dichiarato']))."',".$row['Spadone']."],";
}
?>
]);
var data3 = google.visualization.arrayToDataTable([
['Date', 'Ivo'],
<?php
$query = "SELECT responsabile, sum(val_fattu) as Ivo, data_dichiarato FROM dichiarati_myennova WHERE responsabile = 'ADMRZ11' and dichiarati_myennova.DATA_DICHIARATO > (NOW() - INTERVAL 270 DAY) GROUP BY MONTH(data_dichiarato), responsabile ORDER BY data_dichiarato";
$exec = mysqli_query($con,$query);
while($row = mysqli_fetch_array($exec)){
echo "['".date("Y/m", strtotime($row['data_dichiarato']))."',".$row['Ivo']."],";
}
?>
]);
var data4 = google.visualization.arrayToDataTable([
['Date', 'Montagliani'],
<?php
$query = "SELECT responsabile, sum(val_fattu) as Montagliani, data_dichiarato FROM dichiarati_myennova WHERE responsabile = 'ADMRZ12' and dichiarati_myennova.DATA_DICHIARATO > (NOW() - INTERVAL 270 DAY) GROUP BY MONTH(data_dichiarato), responsabile ORDER BY data_dichiarato";
$exec = mysqli_query($con,$query);
while($row = mysqli_fetch_array($exec)){
echo "['".date("Y/m", strtotime($row['data_dichiarato']))."',".$row['Montagliani']."],";
}
?>
]);
var data5 = google.visualization.arrayToDataTable([
['Date', 'Galtieri'],
<?php
$query = "SELECT responsabile, sum(val_fattu) as Galtieri, data_dichiarato FROM dichiarati_myennova WHERE responsabile = 'ADMRZ21' and dichiarati_myennova.DATA_DICHIARATO > (NOW() - INTERVAL 270 DAY) GROUP BY MONTH(data_dichiarato), responsabile ORDER BY data_dichiarato";
$exec = mysqli_query($con,$query);
while($row = mysqli_fetch_array($exec)){
echo "['".date("Y/m", strtotime($row['data_dichiarato']))."',".$row['Galtieri']."],";
}
?>
]);
var data6 = google.visualization.arrayToDataTable([
['Date', 'Giacometti'],
<?php
$query = "SELECT responsabile, sum(val_fattu) as Giacometti, data_dichiarato FROM dichiarati_myennova WHERE responsabile = 'ADMRZ22' and dichiarati_myennova.DATA_DICHIARATO > (NOW() - INTERVAL 270 DAY) GROUP BY MONTH(data_dichiarato), responsabile ORDER BY data_dichiarato";
$exec = mysqli_query($con,$query);
while($row = mysqli_fetch_array($exec)){
echo "['".date("Y/m", strtotime($row['data_dichiarato']))."',".$row['Giacometti']."],";
}
?>
]);
var data7 = google.visualization.arrayToDataTable([
['Date', 'Mantovani'],
<?php
$query = "SELECT responsabile, sum(val_fattu) as Mantovani, data_dichiarato FROM dichiarati_myennova WHERE responsabile = 'ADMRZ23' and dichiarati_myennova.DATA_DICHIARATO > (NOW() - INTERVAL 270 DAY) GROUP BY MONTH(data_dichiarato), responsabile ORDER BY data_dichiarato";
$exec = mysqli_query($con,$query);
while($row = mysqli_fetch_array($exec)){
echo "['".date("Y/m", strtotime($row['data_dichiarato']))."',".$row['Mantovani']."],";
}
?>
]);
var joinedData = google.visualization.data.join(data1, data2, 'full', [[0, 0]], [1], [1]);
var joinedData2 = google.visualization.data.join(joinedData, data3, 'full', [[0, 0]], [1,2], [1]);
var joinedData3 = google.visualization.data.join(joinedData2, data4, 'full', [[0, 0, 0]], [1,2,3], [1]);
var joinedData4 = google.visualization.data.join(joinedData3, data5, 'full', [[0, 0, 0, 0]], [1,2,3,4], [1]);
var joinedData5 = google.visualization.data.join(joinedData4, data6, 'full', [[0, 0, 0, 0, 0]], [1,2,3,4,5], [1]);
var joinedData6 = google.visualization.data.join(joinedData5, data7, 'full', [[0, 0, 0, 0, 0, 0]], [1,2,3,4,5,6], [1]);
// sort by start and end dates
var chart = new google.visualization.LineChart(document.querySelector('#chart_div'));
chart.draw(joinedData6, {
height: 500,
width: 1400,
interpolateNulls: true,
});
}
google.load('visualization', '1', {packages:['corechart'], callback: drawChart});
</script>
</head>
<body><br /><br />
<div style="width:1500px;" align="center">
<h1 align="center" style="font-size:22px">Produzione SMARTEASY: MYENNOVA (Ultimi 10 Mesi)</h1>
<br />
<div align="center" id="piechart2" style="float:left; width: 700px; height: 390px;"></div>
<div align="center" id="piechart1" style="float:left; width: 700px; height: 390px;"></div>
</div>
<!--Divs that will hold the charts-->
<div id="chart_div"></div>
</body>
</html>