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 |
Jump to:
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
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
Thank you very much, your code worked.
#3
Automatically closed -- issue fixed for 2 weeks with no activity.
#4
i have the same problem..i am using the following code (example2 of the documentation) in a drupal-5.x-node/site:
<?phpfunction 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
#6
See comment #1. The code you pasted is for the Drupal 6 version of fusioncharts.
#7
yep i know..but how looks it in my example?...#1 doesnt works....
#8
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
Try the following
<?phpfunction 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
...I paste this example im my drupal 6 but no charts is displayed !?!
#11
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
<?phpfusioncharts_example2();
?>
#12
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
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:
<?phpfunction 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();
?>