Same issue

msimanga - January 29, 2009 - 17:04
Project:FusionCharts
Version:6.x-1.0
Component:Documentation
Category:support request
Priority:normal
Assigned:Unassigned
Status:active
Description

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:

<?php
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);
}
?>

#1

aaron1234nz - January 29, 2009 - 19:27
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:

<?php
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.

#2

msimanga - January 30, 2009 - 11:51

Thank you very much, your code worked.

#3

System Message - February 13, 2009 - 12:00
Status:fixed» closed

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

#4

fryswe - April 20, 2009 - 19:23

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

<?php
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 :-/

#5

fryswe - April 20, 2009 - 19:25
Status:closed» active

#6

aaron1234nz - April 20, 2009 - 20:26

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

#7

fryswe - April 20, 2009 - 21:23

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

#8

aaron1234nz - April 21, 2009 - 08:36

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.

#9

msimanga - May 1, 2009 - 10:41

Try the following

<?php
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);
}
?>

#10

giomorelli - May 20, 2009 - 11:01

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

#11

aaron1234nz - May 20, 2009 - 11:05

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

<?php
fusioncharts_example2
();
?>

#12

giomorelli - May 20, 2009 - 12:25

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 !

#13

bigknot33 - July 29, 2009 - 16:22
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
();
?>

 
 

Drupal is a registered trademark of Dries Buytaert.