Wally Kolcz

Noobie Question: Fusioncharts With Php Variable

Recommended Posts

I am attempting to create a dashboard using FusionCharts and PHP.

 

I have a XML generator class that seems to produce the correct XML for the chart to form the charts I copied out the results and pasted it into a static document and the chart generate fine. However I have no idea how to use the information in the return variable to actually generate the charts. It keeps failing.

 

When I read the page source it looks right..

var chart_chart1 = new FusionCharts( { "swfUrl" : "assets/FusionCharts/MSColumn3D.swf", "width" : "425", "height" : "300", "renderAt" : "chart1Div", "renderer" : "javascript", "dataFormat" : "xmlurl", "id" : "chart1", "dataSource" : "<chart caption="" XAxisName="" palette="2" animation="1" formatNumberScale="0" numberPrefix="" showValues="0" numDivLines="4" legendPosition="BOTTOM><categories><category label='Total Referrals' /><category label='Total Consults' /></categories><dataset seriesName="Q1"><set value='9668' /><set value='3357' /></dataset><dataset seriesName="Q2"><set value='9154' /><set value='3264' /></dataset><dataset seriesName="Q3"><set value='' /><set value='' /></dataset><dataset seriesName="Q4"><set value='' /><set value='' /></dataset><styles><definition><style type="font" name="CaptionFont" color="666666" size="15" /><style type="font" name="SubCaptionFont" bold="0" /></definition><application><apply toObject="caption" styles="CaptionFont" /><apply toObject="SubCaption" styles="SubCaptionFont" /></application></styles></chart>" } ).render(); Here is my generation string.

 

<?php

//Get this charts data by ID and year

$data = $chardata->getChartXML('2', $_GET['year']);

 

// Set the rendering mode to JavaScript

FC_SetRenderer('javascript');

 

// Call the renderChart method, which would return the HTML and JavaScript required to generate the chart

 

echo renderChart("assets/FusionCharts/MSColumn3D.swf", "$data", "", "chart1", 425, 300, false, true);

?>

 

I've tried the return variable as both the 2nd and 3rd variable.

 

Thanks!

Share this post


Link to post
Share on other sites
Guest Sashibhusan

Hi,

 

Thank you for the post.

 

With regard to your query, it seems that the generated XML posted here is malformed.

 

Please check for the closing (quote) for "legendPosition" attribute value in the <chart> element.

 

Hope this helps!

Share this post


Link to post
Share on other sites

Nope. Sorry, must have been a problem when I copied and pasted it. It has both closing and opening. Good catch though!

 

Hi,

 

Thank you for the post.

 

With regard to your query, it seems that the generated XML posted here is malformed.

 

Please check for the closing (quote) for "legendPosition" attribute value in the <chart> element.

 

Hope this helps!

Share this post


Link to post
Share on other sites
Guest Sashibhusan

Hi,

 

Form the page source code that you have posted, it seems that, you are providing XML data string in place of XML URL argument in the PHP method "renderChart();".

 

Code Snippet:

"dataFormat" : "xmlurl"

 

but "dataSource" : " XML String..."

 

So, could you please provide the XML string ($data) properly , as mentioned below:

 

echo renderChart("assets/FusionCharts/MSColumn3D.swf", "", $data, "chart1", 425, 300, false, true); // Provide $data as a PHP variable (without double quote) for the data string parameter

 

For more information on "Using with PHP > Basic Example > renderChart Parameter Description", please follow the link below:

http://docs.fusioncharts.com/charts/contents/?guide-for-web-developers/php/PHP_BasicExample.html

 

Hope this helps!

Share this post


Link to post
Share on other sites

Thanks for the input, but as I mention in the last line of my original post, I actually tried the $data variable in both the 2nd and 3rd arguments. So I tried them both with no luck.

 

 

Hi,

 

Form the page source code that you have posted, it seems that, you are providing XML data string in place of XML URL argument in the PHP method "renderChart();".

 

Code Snippet:

"dataFormat" : "xmlurl"

 

but "dataSource" : " XML String..."

 

So, could you please provide the XML string ($data) properly , as mentioned below:

 

echo renderChart("assets/FusionCharts/MSColumn3D.swf", "", $data, "chart1", 425, 300, false, true); // Provide $data as a PHP variable (without double quote) for the data string parameter

 

For more information on "Using with PHP > Basic Example > renderChart Parameter Description", please follow the link below:

http://docs.fusionch...sicExample.html

 

Hope this helps!

Share this post


Link to post
Share on other sites
Guest Sashibhusan

Hi,

 

Could you please confirm that you have provided the $data to the 3rd argument without double quotes?

 

If yes, please share the page source code generated, with us.

Share this post


Link to post
Share on other sites

Yep, with and without in the 2nd and 3rd spot.

 

 

 

Hi,

 

Could you please confirm that you have provided the $data to the 3rd argument without double quotes?

 

If yes, please share the page source code generated, with us.

Share this post


Link to post
Share on other sites
Guest Sashibhusan

Yep, with and without in the 2nd and 3rd spot.

 

 

 

 

 

Hi,

 

Could you please try echoing the $data value to the browser and check whether you are getting correct XML string output?

 

It seems rest of the code is correct.

 

So can you share the Firebug console output, if you are getting any error?

 

Also if possible can you please provide us the sample code to replicate the issue from our end?

 

Awaiting inputs from your end.

Share this post


Link to post
Share on other sites

I've been trying to debug it. I ended up just copying out the code from the function directly into a .php page and echoing it back and it works fine. Just confused why the echo works and the return of a variable with the same data fails. If you have an email address, I'll be more than happy to shoot you the view and the class I created to see where my error might be.

 

 

Hi,

 

Could you please try echoing the $data value to the browser and check whether you are getting correct XML string output?

 

It seems rest of the code is correct.

 

So can you share the Firebug console output, if you are getting any error?

 

Also if possible can you please provide us the sample code to replicate the issue from our end?

 

Awaiting inputs from your end.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now