Sign in to follow this  
bender

HELP! using php and MS Access to built dual Y chart

Recommended Posts

 

 

 

<?php

 

//In this example, we show how to connect FusionCharts to a database.

 

//For the sake of ease, we've used an MySQL databases containing two

 

//tables.

 

 

 

// Connect to the DB

 

$link = connectToDB();

 

 

 

//$strXML will be used to store the entire XML document generated

 

//Generate the chart element

 

$strXML = "

 

SYAxisName='Quantity' numberPrefix='$' formatNumberScale='0'>";

 

// Fetch all records

 

$strQuery = "select * from Salexp";

 

$result = odbc_exec($link, $strQuery) or die(odbc_error());

 

 

 

//Iterate through each product

 

if ($result) {

 

while($ors = odbc_fetch_array($result)) {

 

//Now create a second query to get details

 

$strQuery = "SELECT COUNT(revenue) as totrevenue FROM Salexp WHERE product=" . $ors['product'];

 

$result2 = odbc_exec($link, $strQuery) or die(odbc_error());

 

$ors2 = odbc_fetch_array($result2);

 

 

 

$strQuery = "select profit from Salexp where product=" .$ors['product'];

 

$result3 = odbc_exec($link, $strQuery) or die(odbc_error());

 

 

 

$ors3 = odbc_fetch_array($result3);

 

 

 

$strQuery = "select quantity from Salexp where product=" .$ors['product'];

 

$result4 = odbc_exec($link, $strQuery) or die(odbc_error());

 

$ors4 = odbc_fetch_array($result4);

 

 

 

//Generate

 

$strXML .= "";

 

$strXML .= "

 

$strXML .= "";

 

 

 

$strXML .= "";

 

$strXML .= "";

 

 

 

$strXML .= ""

 

$strXML .= "

 

$strXML .= "";

 

 

 

$strXML .= "";

 

$strXML .= "";

 

 

 

//free the resultset

 

odbc_free_result($result2);

 

odbc_free_result($result3);

 

odbc_free_result($result4);

 

}

 

}

 

odbc_close($link);

 

 

 

//Finally, close element

 

$strXML .= "

";

 

 

 

//Create the chart

 

echo renderChart("../FusionCharts/MSCombiDY2D", "", $strXML, "Product Sale", 600, 300, false, false);

 

?>

 

 

 

 

 

 

Edited by Guest

Share this post


Link to post
Share on other sites

***update:

 

 

 

I no longer have the errors...I've fixed the previous code a lil bit...but now my chart does not appear. it just says "Chart."

 

What's wrong?

 

Please someone help me...thanks! I attached the new code below..

php_file.txt

Share this post


Link to post
Share on other sites

Hi! Bender,

We have checked your previous and also updated PHP file, & found that there are still errors on it, that is you are not using the closing tag i.e. "' />" and little more.

Example (as in your code):

$strXML .= "<category label='" .$ors['product'];
$strXML .= "<set value=" .$ors3['profit'];

It should be like:

$strXML .= "<category label='" .$ors['product'] . "'/>";
$strXML .= "<set value='" .$ors3['profit'] . "'/>";

For reference I have modified your previous PHP file, Please have a look on the attached PHP file.

php_file.txt

Edited by Guest

Share this post


Link to post
Share on other sites

thanks for your reply, Rahul..I've tried your solution but there is still no charts displayed..

 

 

 

it only says "Chart."

 

 

 

what's the prob? :ermm:

Share this post


Link to post
Share on other sites

Hi,

Could you please check your FusionCharts.js path? Because PHP API is only drawing the DIV in which 'Chart' text is embedded, & if when the chart is loaded then this text is replaced by the Chart tag.

Share this post


Link to post
Share on other sites

Hi..

 

 

 

I've checked the path and it is correct! maybe it's my Fusionchart coding that is wrong? coz in the documentation, it only shows the php example of a pie chart, and no examples of complicated charts such as this multiple 2 y axis graph...can somebody check what's wrong?

 

 

 

Rahul, thanks for helping me :)

 

 

 

 

 

edit: attached is my latest code

php_file.txt

Edited by Guest

Share this post


Link to post
Share on other sites

Hi Bender,

Could you please send us your directory structure?

And could you try renderChartHTML insted of renderChart just to ensure that everything is OK? 

echo renderChartHTML("../FusionCharts/MSCombiDY2D.swf", "", $strXML, "ProductSale", 600, 300, false);

Share this post


Link to post
Share on other sites

Yay! I changed to RenderChartHTML and it works! well, my graph is shown...but it is not what i expected...must be something wrong with my code...:D

 

 

 

I attached the screenshot of the graph below...the 'intended' look of the graph is in attachment too...

 

 

 

nasha.jpg --> currently

 

 

 

graph.jpg --> suppossed to look like this

post-2656-128441567333_thumb.jpg

post-2656-128441567357_thumb.jpg

Share this post


Link to post
Share on other sites

thanks so much Rahul for helping me! can you tell me what's the difference between renderChart and renderChartHTML? i will go and check the FusionCharts.js path...

 

 

 

if it's not a problem, can you please explain to me what i did wrong in the while loop? the file that you've modified works fine and it makes me very excited and curious :D

 

 

 

thanks a million!!

Share this post


Link to post
Share on other sites

Rahul,

 

My mind is boggling...can't find anything wrong with the path.

 

 

 

Let me explain:

 

 

 

My main project folder in www root is named 'Nashgraph'. Inside it I have 2 more folders called 'Codings' and 'FusionCharts'. I store the 'FusionCharts.js' file, swf files and 'includes' under the 'FusionCharts' folder. All my written codes are in 'Codings' folder.

 

 

 

So, i think my path in the code is right already, no? i.e: "../FusionCharts/FusionCharts.js" :D

Share this post


Link to post
Share on other sites

Hi,

The difference between renderChart and renderChartHTML is that, renderChart embeds JavaScript tag which calls the FusionCharts method that is in FusionCharts.js. By using the JavaScript you don't get the message "click to activate" if used in IE. Where as renderChartHTML just embeded the Charts using the <Object> tag. Both methods are defined in the FusionCharts.php file, but one requires the FusionCharts.js.

Problem in your loop was that it was creating category & dataset element for each records.

Share this post


Link to post
Share on other sites

Hi,

Could you please confirm that the Web page/Web Application where you are rendering the chart is located in Coding folder? If so, then the path is correct.You might try FusionCharts/... in any case if you are putting the main file in Nashgraph folder.

Share this post


Link to post
Share on other sites

sorry i didn't reply soon...it was the weekend...hehe :)

 

 

 

okay i still can't do that...and I don't know why. can i just use renderChartHTML? what's the pro and cons?

 

 

 

next thing i want to know, can yo tell me how to make all 3 entity into line graphs? means that there will be 3 lines in the graph...thanks for helping!

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