Ayan Pal

Combination chart (2 y-axes) from Database ?

Recommended Posts

Hi. I am seeking help with setting up a Combination (two Y-Axes) chart using the PHP-Class and reading the data from a MySQL database. I have already successfully done a Single-Series (one Y-Axis) chart with php/mysql. But I don't see anywhere in the docs an exact example of the required php code for doing a Combination chart from a database.

 

 

 

My database looks like this:

 

ID YEAR TOPIC MY_VALUE

 

1 1994 revenue 140000

 

2 1995 revenue 560000

 

3 1996 revenue 420000

 

4 1994 sales 6000

 

5 1995 sales 24000

 

6 1996 sales 18000

 

 

 

I want the Combination chart to show:

 

X-axis : YEAR

 

Y-axis Left : REVENUE

 

Y-axis Right : SALES

 

 

 

So on the chart the X-axis categories would show the 3 Years (1994, 1995, and 1996).

 

The left Y-axis would show Revenue values (140000, 560000, 420000).

 

And the right Y-axis would show Sales values (6000, 24000, 18000).

 

 

 

When I did a Single-Series chart, I read from the database with $FC->addDataFromDatabase. For the Combination chart, I think I need to use $FC->addDatasetsFromDatabase but I can't find enough documentation/sample code for that. I would think I need to use two different database queries, one for each dataset (for each y-axis). Is that incorrect?

 

 

 

In the docs (/FusionCharts_Evaluation/Contents/PHPClassAPI/Functions.html), i found

 

addDatasetsFromDatabase(resource $query_result, string $ctrlField, string $valueField[, array $datasetParamArray, string $link]) 

 

 

 

I tried this but it didn't work:

 

 

 


strQuery1 = "SELECT ID, Year, Topic, My_Value FROM myTable WHERE Topic='revenue' ORDER BY Year ASC ";

strQuery2 = "SELECT ID, Year, Topic, My_Value FROM myTable WHERE Topic='sales' ORDER BY Year ASC ";



$result1 = mysql_query($strQuery1) or die(mysql_error());

$result2 = mysql_query($strQuery2) or die(mysql_error());



$FC->addDatasetsFromDatabase($result1, "Year","My_Value");

$FC->addDatasetsFromDatabase($result2, "Year","My_Value");



$FC->renderChart();

 

 

 

Any help GREATLY appreciated. Thanks! Todd

Share this post


Link to post
Share on other sites

Hi Toddz70,

Please change your code like this:

$datasetParamArray=array("parentYAxis=S");////// delimeter seperated parameters for the dataset don't use (") for parameter values

$FC->addDatasetsFromDatabase($result2, "Year","My_Value",$datasetParamArray);  //this dataset will render as secondary y-axis

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