There are two common mistakes that causes problems with input data.
The indexes in the data array has missing keys. The library assumes that the data array has consecutive values indexed from 0 and upwards. This means that the following data array specification is illegal
1 | $data = array( 1 => 23, 2 => 14, 3 => 17 ) ; |
The problem with the array above is that it lacks the 0 key. A similar problem is to have a missing index, such as
1 | $data = array( 0 => 23, 2 => 14, 3 => 17 ) ; |
If E_NOTICE
is not enabled in
php.ini
then this mistake will give the
(slightly misleading) error message shown in Figure 13.7. Error when only null values are specified. If full error checking is
enabled in php.ini then these types of problem will give the standard
PHP error message shown in Figure 13.8. PHP (HTML) error when missing data keys. This shows a PHP setup
which has HTML errors enabled. Note the JpGraph textual error string at
the bottom of the second PHP error message box.
Another typical mistake caused by "faulty data" is different convention for specifying decimal data. PHP and the library assumes that decimal data used "." (point) to separate the integer from the decimal part of a number. Some locales uses "," (comma) to do this separation. This means that the following code will not work.
1 | $data = array( 0 => '12,0', 1 => '18,0', 2 => '15,0' ) ; |
Again, if E_NOTICE
is not enabled in
php.ini
then this mistake will give the
(slightly misleading) error message shown in Figure 13.7. Error when only null values are specified