diff --git a/htdocs/core/class/dolgraph.class.php b/htdocs/core/class/dolgraph.class.php index ac603837240..7c368437ffc 100644 --- a/htdocs/core/class/dolgraph.class.php +++ b/htdocs/core/class/dolgraph.class.php @@ -71,7 +71,7 @@ class DolGraph var $showlegend=1; var $showpointvalue=1; var $showpercent=0; - + var $graph; // Objet Graph (Artichow, Phplot...) var $error; @@ -254,7 +254,7 @@ class DolGraph { $this->datacolor = $datacolor; } - + /** * Set type * @@ -395,7 +395,7 @@ class DolGraph /** * Show legend or not - * + * * @param int $showlegend 1=Show legend (default), 0=Hide legend * @return void */ @@ -406,7 +406,7 @@ class DolGraph /** * Show pointvalue or not - * + * * @param int $showpointvalue 1=Show value for each point, as tooltip or inline (default), 0=Hide value * @return void */ @@ -414,10 +414,10 @@ class DolGraph { $this->showpointvalue=$showpointvalue; } - + /** * Show percent or not - * + * * @param int $showpercent 1=Show percent for each point, as tooltip or inline, 0=Hide percent (default) * @return void */ @@ -425,9 +425,9 @@ class DolGraph { $this->showpercent=$showpercent; } - - - + + + /** * Define background color of complete image * @@ -590,12 +590,18 @@ class DolGraph /** * Build a graph onto disk using correct library * - * @param string $file Image file name to use if we save onto disk + * @param string $file Image file name to use to save onto disk (also used as javascript unique id) * @param string $fileurl Url path to show image if saved onto disk * @return void */ function draw($file,$fileurl='') { + if (empty($file)) + { + $this->error="Call to draw method was made with empty value for parameter file."; + dol_syslog(get_class($this)."::draw ".$this->error, LOG_ERR); + return -2; + } if (! is_array($this->data) || count($this->data) < 1) { $this->error="Call to draw method was made but SetData was not called or called with an empty dataset for parameters"; @@ -796,8 +802,8 @@ class DolGraph * $this->mode = 'depth' ??? * $this->bgcolorgrid * $this->datacolor - * - * @param string $file Image file name to use if we save onto disk + * + * @param string $file Image file name to use to save onto disk (also used as javascript unique id) * @param string $fileurl Url path to show image if saved onto disk * @return void */ @@ -807,6 +813,12 @@ class DolGraph dol_syslog(get_class($this)."::draw_jflot this->type=".join(',',$this->type)); + if (empty($this->width) && empty($this->height)) + { + print 'Error width or height not set'; + return; + } + $legends=array(); $nblot=count($this->data[0])-1; // -1 to remove legend if ($nblot < 0) dol_print_error('Bad value for property ->data. Must be set by mydolgraph->SetData before callinf mydolgrapgh->draw'); @@ -823,7 +835,7 @@ class DolGraph // Fill array $values $x=0; - foreach($this->data as $valarray) // Loop on each x + foreach($this->data as $valarray) // Loop on each x { $legends[$x] = $valarray[0]; $values[$x] = (is_numeric($valarray[$i+1]) ? $valarray[$i+1] : null); @@ -839,12 +851,12 @@ class DolGraph { foreach($values as $x => $y) { if (isset($y)) $serie[$i].='d'.$i.'.push(['.$x.', '.$y.']);'."\n"; } } - + unset($values); $i++; } $tag=dol_escape_htmltag(dol_string_unaccent(dol_string_nospecial(basename($file),'_',array('-','.')))); - + $this->_stringtoshow =''."\n"; if (! empty($this->title)) $this->_stringtoshow.='