Sign in to follow this  
FusionCharts Support

Combination Charts with php and MySQL

Recommended Posts

Is it possible to generate a "single axis" combination chart from MySQL data using php class? I need to plot "columns" "lines" and "areas" on the same chart AND on the same axis. Coould someone please help with an explanation and some sample code?

Share this post


Link to post
Share on other sites
Guest Rajroop

Hello Charles,

 

 

 

Welcome to the FusionCharts Forum. :D

 

 

 

Could you please refer to the following link and see if it suits your requirements?

 

(Ref: http://www.fusioncharts.com/docs/Contents/ChartSS/Combi2D.html)

 

 

 

On more information on FusionCharts and PHP Class, could you please visit our online documentation and click on the Guide for Web Developers section, on the left hand menu panel and try again? The section FusionCharts PHP Class has all the examples you need for this.

 

 

 

I hope this helps. :D

Share this post


Link to post
Share on other sites

Dear Rajroop:

 

 

 

Thank you for your reply. I am very familiar with both of the references you provided. I am an experienced FusionCharts user, and I have had great success generating charts of all types from the FusionCharts and PowerCharts portfolio. They are beautiful and professional, and I always receive comments regarding them. Until now, I have been using ".xml" data files coupled with ".html" parent files, which would define the path/filename of the data file, set the size parameters, number of charts on the page, etc.

 

 

 

Now I have a need to produce these charts from data being stored in MySQL. I have been able to follow your examples from the documentation and have modified them to develop several of my own graphs. However, I need to make the combination charts similar to what I have made in the past (similar to what is shown in the reference you provided) using php from MySQL data. I wish to pass the variable directly from MySQL because I do not want to use the URL or xml method.

 

 

 

I am unclear on how to call the correct chart and how to pass the category names, data, and parameters such as renderAs='Line' or renderAs='Area'. I do not expect to have any trouble with the MySQL strings, but I need a little help with the php. Can you please help me with a detaiked explanation of how to do this or some sample code?

 

 

 

Thank you in advance for helping me in this matter.

 

 

 

Respectfully,

 

 

 

Charles Thomas Standard

Share this post


Link to post
Share on other sites
Guest Rajroop

Hello Charles,

 

 

 

Thank you for your kind words.

 

 

 

I wish to pass the variable directly from MySQL because I do not want to use the URL or xml method.

 

 

 

I understand you requirements. However, this is not possible using FusionCharts, as of now. :D You have to use the dataURL/dataXML method to feed the data and implement the data plot specifications.

Share this post


Link to post
Share on other sites

Thanks for the help on this one. It turns out that it is is possible. :D

 

 

 

The problem all along was the format of the array that passes the dataset parameters to the

 

 

 

I hope this little snippet of code will help others to see how to do it. I only added paremeters for color and renderAs, just to prove the array syntax was correct.

 

 

 

# Fetch all necessary database records creating SQL query

 

$strQuery = "select Height,Weight,Fecha from php_Charts where Name=" . $person . " order by Fecha";

 

 

 

$result = mysql_query($strQuery) or die(mysql_error());

 

 

 

#Pass the SQL query result and format to PHP Class Function

 

# this function will automatically add chart data from database

 

 

 

if ($result) {

 

 

 

# Add category names --- Appears not to be needed with datasetsa

 

# $FC->addCategoryFromDatabase($result, "Fecha");

 

 

 

$ctrlField = "Fecha";

 

$valueField = "Height;Weight";

 

$datasetParamArray = array("renderAs=Area; Color=008800",

 

"Color=880000; ");

 

 

 

$FC->addDatasetsFromDatabase($result,$ctrlField,$valueField,$datasetParamArray,"");

 

 

 

}

 

 

 

mysql_close($link);

 

 

 

# Create the chart

 

$FC->renderChart();

 

?>

 

 

 

Thanks again! Happy Charting!

Share this post


Link to post
Share on other sites
Guest Rajroop

That's great, Charles.

 

 

 

Thank you for sharing this. :D

 

 

 

Happy FusionCharting yourself. :D

Share this post


Link to post
Share on other sites

Rajroop,

 

 

 

I am also looking at using FusionCharts with MySQL. I have just stumbled across Charles' solution so I haven't had time to try it out. But I think you should develop a section in the documentation to explore this idea.

 

 

 

Our problem is that while we like Fusion Charts alot, the burden of updating all the XML is starting to drag the whole project down. If we could have FusionCharts fetch the data directly off a MySQL database, that would be fantastic.

 

 

 

John

Share this post


Link to post
Share on other sites

Charles,

 

 

 

Even though it is not supposed to work, would you be willing to explain a bit more about how you get Fusion Charts to access the data from a MySQL database?

 

 

 

I was unable to make your code snippet work (although that it certainly due to my newbie level skills).

 

 

 

Thanks & Regards,

 

 

 

John

Share this post


Link to post
Share on other sites

Hello Charles (And everybody else)

I have set up a chart (Doughnut3D) to show as in Charle's example.

And have a few questions...

1.) I dont seem to be able to show the different slices names? (Tried to set showNames=1 but to no use.)

And to make it more complicated...

2.) I want to be able to press one of the slices (dataURL) and load a second chart from what I pressed (New SQL query with new variables).

Is this possible with PHP Class?

(I have the above set up now on two separate *.php pages, and let the variables I create pass to the second page with urlencode. But it would be sooo neat to have it all in same page...) :-)

3.) Does anyone know if there's a way to pass variables to mySQL other than like inserts into for e.g a temptable? (Maby completely wrong forum, but I think the knowledge is here.)

regards Emanuel

Share this post


Link to post
Share on other sites

Hello Rahul,

I've dropped the phpclass-trail... :-)

I've made an new question in this forum instead regarding URL and XML methods of transfering variables and data to a second chart in same page.

Have trouble understanding how to make more than one variable (as in your example) go to Detailed.php

/Emanuel

Share this post


Link to post
Share on other sites

Hi Emanuel,

To pass multiple values to a file using query string you would need to URL Encode the URL. This would depend on the implementation that you are doing at your end which I am aware. So, can not state specifically where exactly you need to do this.

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
Sign in to follow this