Dynamic SQL query for Fusion Chart PHP

Recommended Posts


I’m relatively new to Fusion Charts but have been enjoying trying things out with the PHP wrapper.

I want to pull data from a local MySQL database using a suitable query and display it in a line plot. As a first attempt I followed the first example on this Fusion Charts page, changed the variables to those in my database, updated the sql query, swapped the bar chart to a line plot and hey presto, everything works!

The trouble is, the sql query is hard coded in the PHP. I’m ideally looking to have a web page which has options (drop down menus etc) for the user to select what is plotted based on fields within the MySQL database. The example given showed populations in various countries but the options would allow the user to choose either that or perhaps average number of days people are at work in each country. The other fields would be present in the MySQL database and the user selectable fields would be used to update the query before re-plotting the Fusion Chart. Essentially I just wanted to be able to generate the MySQL query based on user selections before the plot is drawn.

I’m not looking for a complete solution here just some guidance on how to go about this.

Any help greatly appreciated!

Share this post

Link to post
Share on other sites


FusionCharts natively can't interpret with data.
You have to form a SQL query based on properties selected by the user and then form JSON data corresponding to FusionCharts format by using the data fetched and then pass it to FusionCharts.

Please refer the sample given here:

You can also refer the sample fiddle given here to know more about the JSON format. :
Hope this will help.

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