0

I have been trying to integrate the Fusioncharts library with my Drupal 7 site.

Just to check if everything is working properly, I followed this documentation for creating a basic graph with data contained in Data.xml file; the entire documentation is here.

FYI, I need to use PHP as I am more comfortable with it.

I have extracted the downloaded folder into /sites/all/libraries/FusionChartsFree/; with changes in paths (nothing else); I have pasted the code in the given example into my Drupal 7 node with the php input filter enabled. I also have the libraries module installed.

<?php
  //We've included ../Includes/FusionCharts_Gen.php, which contains FusionCharts PHP Class
  //to help us easily embed the charts.
  $name = "FusionChartsFree";
  if ($path = libraries_get_path($name)) {
    include $path . '/Code/PHP/Includes/FusionCharts.php';
  }
?>
<html>
  <head>      
    <?php
      //You need to include the following JS file, if you intend to embed the chart using JavaScript.
      //When you make your own charts, make sure that the path to this JS file is correct. Else, you
      //would get JavaScript errors.

      include($path.'/Code/FusionCharts/FusionCharts.js');
    ?> 
    <script type="Javascript" SRC="/sites/all/libraries/FusionChartsFree/Code/FusionCharts/FusionCharts.js"></SCRIPT>
    <title>FusionCharts - Simple Column 3D Chart</title> 
  </head>
  <body>
    <?php
      //Create the chart - Column 3D Chart with data from Data/Data.xml
      echo renderChart("/sites/all/libraries/FusionChartsFree/Code/FusionCharts/Column3D.swf", "/sites/all/libraries/FusionChartsFree/Code/PHP/BasicExample/Data/Data.xml", "", "myFirst", 600, 300, false, true); 
   ?>
  </body>
</html>

I get the below output. It is pretty long; hence, I have put then in part by part in these pictures.

enter image description here

enter image description here

enter image description here

enter image description here

enter image description here

(FYI, those Flash files that appear in the output, do not display anything if I click on them.)

Now, suppose I remove the below line from the code.

<?php
 include $path . '/Code/FusionCharts/FusionCharts.js';
?>

I get nothing. I mean only a text which reads "cahrt" in the below output.

enter image description here

My Question: How can I make Fusioncharts work in DRUPAL 7?

I am also having similar trouble with the pChart library too: Even pChart does not display anything, not even an error, or warning. Simply there is nothing in the node body.

2 Answers 2

2

There's a couple of problems in your code:

  • include($path.'/Code/PHP/Includes/FusionCharts.php'); you have to use ./ to include files.
  • include($path.'/Code/FusionCharts/FusionCharts.js'); you should use drupal_add_js() to include javascript in your code.
  • FusionCharts documentation seems a little old as Column3D.swf is now FCF_Column3D.swf

Here is a working example, I haven't used the librarie module but you should be able to adapt it easily. I put this code in a node with PHP filter activated.

<?php
$file = './sites/all/libraries/FusionChartsFree/Code/PHP/Includes/FusionCharts.php';
if (is_file($file)) {
  require_once $file;
}
drupal_add_js('sites/all/libraries/FusionChartsFree/Code/FusionCharts/FusionCharts.js');

//Create the chart - Column 3D Chart with data from Data/Data.xml
echo renderChart("/sites/all/libraries/FusionChartsFree/Code/FusionCharts/FCF_Column3D.swf", "/sites/all/libraries/FusionChartsFree/Code/PHP/BasicExample/Data/Data.xml", "", "myFirst", 600, 300, false, true); 

?>
10
  • Thank you so much..!! But still I have small problem, I get a flash player icon hwere I can click it load the graph. but when I click it, its empty..! Commented Feb 25, 2012 at 5:19
  • before I click, oi44.tinypic.com/300s0i8.jpg after I click, oi39.tinypic.com/33z7f5v.jpg Commented Feb 25, 2012 at 5:21
  • Also can you tell me how to do it in phpclass.of fusionchart..? I followed this documentation , made the necessary cahnges as u said (about the path and adding js) docs.fusioncharts.com/free/Contents/PHPClass_BasicExamples.html . But all I see is a text "chart" on my node.FYI, I tried both examples given on that page and got same results. Am getting too frustrated with this..:( So please help me. Commented Feb 25, 2012 at 6:41
  • This is rather strange, using the code as is works for me in chrome: i.imgur.com/UzWFx.png For the PHPClass the only important thing is to get the ` $FC->setSwfPath("../../FusionCharts/");` path correctly.
    – tostinni
    Commented Feb 26, 2012 at 18:07
  • I done everything properly..!! I have no idea what to do.. how can I create graphs now..?? I tried flot module but even that having problems,drupal.stackexchange.com/questions/23588/… Commented Feb 27, 2012 at 3:54
0

Finally, it worked. I don't know exactly what the problem is, but here is what I did.

  • I uninstalled all other modules related to charting
  • I downloaded FusionchartFree again
  • I sed the Libraries module
  • I checked with the following code, and it worked.

    $name = "FusionChartsFree";
    if ($path = libraries_get_path($name)) {    
      include $path . '/Code/PHP/Includes/FusionCharts.php';
      drupal_add_js($path.'/Code/FusionCharts/FusionCharts.js');
    }
    
    // Create the chart - Column 3D Chart with data from Data/Data.xml
    
    echo renderChart($path.'/Charts/FCF_Column3D.swf', $path.'/Code/PHP/BasicExample/Data/Data.xml', "", "myFirst", 600, 300, false, true); 
    

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.