Hi, I must be missing something. Does anyone have a single working example for 6.x?

I've installed the charts and google_charts modules and the settings page shows rendered charts so it does indeed work. However, the code examples seem out of date. Here's is what I've tried:

$chart = array(
'#chart_id' => 'test_chart',
'#title' => t('Servings'),
'#type' => CHART_TYPE_PIE_3D, // where is this constant defined?
);
$chart['#data']['fruits'] = 3;
$chart['#data']['meats'] = 2;
$chart['#data']['dairy'] = 5;

// echo charts_chart($chart); // result: "This type is not possible using Google Chart"
// echo theme('chart', array('chart' => $chart)); // does nothing
// echo chart_render($chart); // result: "Call to undefined function chart_render()"

The wiki examples all look like this one and all use the undefined function "chart_render". What am I missing?

Comments

quickcel’s picture

Take a look at the examples page and copy the code for the first chart (simple pie chart): http://code.google.com/p/drupal-chart-api/wiki/Examples

I'm guessing you might not be using the php filter for your charts, but this is what I just used and it is rendering fine:

<?php

$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;

echo chart_render($chart);

?>
chadj’s picture

Call to undefined function chart_render()

Which is not surprising since, looking through the module code, there is no function "chart_render".

chadj’s picture

Also, the constants like CHART_TYPE_PIE_3D are not defined anywhere.

I did a print_r on the chart data being sent to charts_chart() and got a very different structure, which now works:

  $chart = array(
      '#chart_id' => 'test_chart_tracked',
      '#title' => t('Tracked Data'),
      '#type' => 'pie3D',
    ); 
  $chart[] = array ( 
     array('#value' => $tracked,  '#label' => 'tracked'),
     array('#value' => $untracked,  '#label' => 'other'), 
  );   
 $chart_rendered = charts_chart($chart); 

But there is no documentation matching this structure.

chadj’s picture

Status: Active » Closed (fixed)

I'm an idiot.

I typed "drush dl charts" instead of "drush dl chart" and ended up in an alternate Google charting universe.

No wonder documentation did not quite match.