Support of null values in graph

This commit is contained in:
Laurent Destailleur 2020-03-09 22:52:30 +01:00
parent e1c7222172
commit cc1a02f0ea

View File

@ -965,9 +965,13 @@ class DolGraph
$legends = array(); $legends = array();
$nblot = 0; $nblot = 0;
if (is_array($this->data) && is_array($this->data[0])) { if (is_array($this->data)) {
$nblot = count($this->data[0]) - 1; // -1 to remove legend foreach ($this->data as $valarray) // Loop on each x
{
$nblot = max($nblot, count($valarray) - 1); // -1 to remove legend
}
} }
//var_dump($nblot);
if ($nblot < 0) dol_syslog('Bad value for property ->data. Must be set by mydolgraph->SetData before calling mydolgrapgh->draw', LOG_WARNING); if ($nblot < 0) dol_syslog('Bad value for property ->data. Must be set by mydolgraph->SetData before calling mydolgrapgh->draw', LOG_WARNING);
$firstlot = 0; $firstlot = 0;
// Works with line but not with bars // Works with line but not with bars
@ -1000,17 +1004,20 @@ class DolGraph
); );
} else { } else {
$tmpvalue = (array_key_exists('y_'.$i, $valarray) ? $valarray['y_'.$i] : $valarray[$i + 1]); $tmpvalue = (array_key_exists('y_'.$i, $valarray) ? $valarray['y_'.$i] : $valarray[$i + 1]);
//var_dump($i.'_'.$x.'_'.$tmpvalue);
$values[$x] = (is_numeric($tmpvalue) ? $tmpvalue : null); $values[$x] = (is_numeric($tmpvalue) ? $tmpvalue : null);
} }
$x++; $x++;
} }
//var_dump($values);
$j = 0; $j = 0;
foreach ($values as $x => $y) { foreach ($values as $x => $y) {
if (isset($y)) { if (isset($y)) {
$serie[$i] .= ($j > 0 ? ", " : "").$y; $serie[$i] .= ($j > 0 ? ", " : "").$y;
$j++; } else {
$serie[$i] .= ($j > 0 ? ", " : "").'null';
} }
$j++;
} }
$values = null; // Free mem $values = null; // Free mem