I am more of a DBA and not a PHP type of person. I tried pasting the sample in from the API.txt document into a normal page. I set the input format to PHP but nothing displays. I checked that the query did indeed return some records. Is it possible to create a chart in this way or am I barking up the wrong tree?

This is what my page content had in it:

function fusioncharts_example1() {
  return fusioncharts_render(FUSIONCHART_QUERY, 'example1');
}

function example1_fusionchart_callback($args = NULL) {
  $query = "SELECT t.name AS name, COUNT(*) as value FROM {term_data} t JOIN {term_node} tn ON t.tid = tn.tid WHERE t.vid=2 GROUP BY t.tid";
  $type = 'Column 3D';
  $settings = array('Caption' => 'Sample chart using the API and a query to generate the data');
  $attributes = array();
  $width = 500;
  $height = 300;
	
  return array($query, $type, $settings, $attributes, $width, $height);
}

Comments

aaron1234nz’s picture

Status: Active » Fixed

Yes you can create charts in this way.
To use this function by entering PHP into a page, You need to echo the result of the fusionchart_render function, and take it outside the function definition. Try using this code:

echo fusioncharts_render(FUSIONCHART_QUERY, 'example1');


function example1_fusionchart_callback($args = NULL) {
  $query = "SELECT t.name AS name, COUNT(*) as value FROM {term_data} t JOIN {term_node} tn ON t.tid = tn.tid WHERE t.vid=2 GROUP BY t.tid";
  $type = 'Column 3D';
  $settings = array('Caption' => 'Sample chart using the API and a query to generate the data');
  $attributes = array();
  $width = 500;
  $height = 300;
	
  return array($query, $type, $settings, $attributes, $width, $height);
}

Note: this code is for the Drupal 5 version of this module only. The API has changed for the Drupal 6 version.

msimanga’s picture

Thank you very much, your code worked.

Status: Fixed » Closed (fixed)

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

fryswe’s picture

i have the same problem..i am using the following code (example2 of the documentation) in a drupal-5.x-node/site:

function fusioncharts_example2() {
  $info->data = array(array('Cat', 1),
                array('Dog', 2),
                array('Pig', 3),
     		    array('Mouse', 4),
	         );
  $info->type = 'Column 3D';
  $info->settings = array('Caption' => 'Sample chart using the API and sample data');
  $info->attributes = array('callback' => 'example2',
                      'color' => array('121212', 'ff0000'), //no # in front of color
                      'trendline' => array(
                                      'startvalue' => 5,
                                      'displayvalue' => 'Test',
                                      'color' => '0000ff'
                                     )
                      ); 
  $info->width = 500;
  $info->height = 300;
  return theme('fusionchart', $info);
}

but my chart won't be displayed :-/

fryswe’s picture

Status: Closed (fixed) » Active
aaron1234nz’s picture

See comment #1. The code you pasted is for the Drupal 6 version of fusioncharts.

fryswe’s picture

yep i know..but how looks it in my example?...#1 doesnt works....

aaron1234nz’s picture

Are you sure you installed the Drupal 5 version. The code in comment #1 should work. The reason I ask is that if you found the code you pasted in #4 in the api file, then you have the wrong version.

msimanga’s picture

Try the following

function fusioncharts_example2() {
  $info->data = array(array('Cat', 1),
                array('Dog', 2),
                array('Pig', 3),
                 array('Mouse', 4),
             );
  $info->type = 'Column 3D';
  $info->settings = array('Caption' => 'Sample chart using the API and sample data');
  $info->attributes = array('callback' => 'example2',
                      'color' => array('121212', 'ff0000'), //no # in front of color
                      'trendline' => array(
                                      'startvalue' => 5,
                                      'displayvalue' => 'Test',
                                      'color' => '0000ff'
                                     )
                      );
  $info->width = 500;
  $info->height = 300;
  echo theme('fusionchart', $info);
}
giomorelli’s picture

...I paste this example im my drupal 6 but no charts is displayed !?!

aaron1234nz’s picture

If you are referring to the code in comment#9 then you will also need to call this function. add this line at at the top or bottom

fusioncharts_example2();
giomorelli’s picture

Yes , code is from comment #9....I add yor line, but this is the output..

START Code Block for Chart DrupalFusionChart_1

END Code Block for Chart DrupalFusionChart_1

the previus line are coment .

...and no picture !

bigknot33’s picture

Title: Sample » Same issue
Version: 5.x-1.0-beta4 » 6.x-1.0

The code in #9 shows blank - the line
$info->type = 'Column 3D';
should be
$info->chart_type = 'Column 3D';

This code (Drupal 6) should work:

<?php
function fusioncharts_example2() {
  $info->data = array(array('Cat', 1),
                array('Dog', 2),
                array('Pig', 3),
                 array('Mouse', 4),
             );
  $info->chart_type = 'Column 3D';
  $info->settings = array('Caption' => 'Sample chart using the API and sample data');
  $info->attributes = array('callback' => 'example2',
                      'color' => array('121212', 'ff0000'), //no # in front of color
                      'trendline' => array(
                                      'startvalue' => 5,
                                      'displayvalue' => 'Test',
                                      'color' => '0000ff'
                                     )
                      );
  $info->width = 500;
  $info->height = 300;
  echo theme('fusionchart', $info);
}
?>
<?php
fusioncharts_example2();
?>
aaron1234nz’s picture

Status: Active » Closed (works as designed)

There has been no traffic on this issue for 2 years so closing.