Hi guys
Using in my own module

$chart = array(
  '#chart_id' => 'test_chart',
  '#title' => t('Servings'),
  '#type' => CHART_TYPE_PIE_3D,
);

$chart['#data']['fruits'] = 3;
$chart['#data']['meats']  = 2;
$chart['#data']['dairy']  = 5;

$chart['#labels'][] = t('Fruits');
$chart['#labels'][] = t('Meats');
$chart['#labels'][] = t('Dairy');

return theme('chart', array('chart' => $chart));

i get

Notice: Uninitialized string offset: 0 in _chart_is_valid_size() (line 755 of \sites\all\modules\chart\chart.module).
Notice: Uninitialized string offset: 0 in _chart_is_valid_size() (line 755 of \sites\all\modules\chart\chart.module).

the pie chart does display but how to get rid of these notices please

CommentFileSizeAuthor
#4 chart-size-notice-1205408-4.patch624 bytes13rac1

Comments

mineshaftgap’s picture

I did not find this documented, but this fixed if for me:

$chart = array(
  '#chart_id' => 'test_chart',
  '#title' => t('Servings'),
  '#type' => CHART_TYPE_PIE_3D,
	'#size' => array('#width' => 640, '#height' => 480)
);
maori’s picture

Thanks that worked a treat here also

pelonbiologo’s picture

Hi,

This solution also worked for me, but it still does not allow for the chart to be re-sized. It seems that the Uninitialized string notice disappears when adding the '#size' key/value pair to the array, but the values for #width and #height are ignored.

Any ideas on how to change the size of the charts?

13rac1’s picture

Title: need help with Uninitialized string offset: 0 in _chart_is_valid_size() » Missing size array causes Notices: Uninitialized string offset: 0 in _chart_is_valid_size()
Version: 7.x-1.0 » 7.x-1.x-dev
Priority: Major » Normal
Status: Active » Needs review
StatusFileSize
new624 bytes

Patch for 7.x-1.x-dev is attached. Fixes original problem of notices and adds a watchdog call when size is greater than 300,000 pixels.

@pelonbiologo If size (heightXwidth) is greater than 300,000 pixels, it will be ignored. Is it?

13rac1’s picture

Version: 7.x-1.x-dev » 6.x-1.x-dev
Status: Needs review » Patch (to be ported)

Committed to 7.x-1.x-dev. Probably needed in 6.x-1.x-dev.

13rac1’s picture

Status: Patch (to be ported) » Fixed

Applied to 6.x-1.x.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

leszek.hanusz’s picture

Version: 6.x-1.x-dev » 7.x-1.x-dev
Status: Closed (fixed) » Active

Hmm it seems the problem is not fixed for the latest 7.x-1.x-dev version.

I think you should replace
if(!empty($value))
by
if(empty($size))

Merick’s picture

I agree with #8. I also changed the following line in chart_build() and the notice message has gone away:

$chart += array(
      '#title' => '',
      '#size' => '', 
....

To:

$chart += array(
      '#title' => '',
      '#size' => array(),
....
13rac1’s picture

Status: Active » Fixed

Ah ha! Fixed in 6.x and 7.x.
http://drupalcode.org/project/chart.git/commit/8408f06
http://drupalcode.org/project/chart.git/commit/678869f

diff --git a/chart.module b/chart.module
index 68b1b5c..93e56da 100644
--- a/chart.module
+++ b/chart.module
@@ -292,7 +292,7 @@ function chart_build($chart) {
     // Merge optional parameters defaults.
     $chart += array(
       '#title' => '',
-      '#size' => '',
+      '#size' => array(),
       '#legends' => array(),
       '#legend_position' => '',
       '#labels' => array(),
@@ -834,10 +834,10 @@ function _chart_error($message, $admin = TRUE) {
  * Check if chart data is below size limit.
  */
 function _chart_is_valid_size($size) {
-  if (!empty($value)) {
+  if (empty($size)) {
     return FALSE;
   }
-  if (!is_numeric($size['#width']) && !is_numeric($size['#height'])) {
+  if (!is_numeric($size['#width']) || !is_numeric($size['#height'])) {
     return FALSE;
   }
 

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.