Jump to content


Fusion Charts/sql Noob!


  • Please log in to reply
20 replies to this topic

#1 DJ-DOO

DJ-DOO

    Forum Member

  • Members
  • PipPipPipPip
  • 25 posts

Posted 14 May 2012 - 09:32 AM

Hi,

First of all apologies for any idiocies I may come out with as I am a noobie to fusion charts and sql. I'm just trying to chart data in an sql database with one table that has two fields Date and Result. The result is either approved or not approved. I'm trying to chart how many have been approved in each month...@ present I'm just trying to chart how many have been approved without grouping by date. I've been working on the piechart example, I've tried editing to accomodate my needs but all that is displaying is 'Chart' and no chart. Posted Image I know I have done something or many things wrong and I'm sure they're stupid mistakes, I'm just not sure where to go, I just need this to get me going, I can do anymore based on this...I've posted what I've done below, so if anyone can help I would greatly appreciate it!

Regards,
Gary



<?php
//We've included ../Includes/FusionCharts.php and ../Includes/DBConn.php, which contains
//functions to help us easily embed the charts and connect to a database.
include("../Includes/FusionCharts.php");
include("../Includes/DBConn.php");
?>
<HTML>
<HEAD>
	<TITLE>
	FusionCharts Free - Database Example
	</TITLE>
	<?php
	//You need to include the following JS file, if you intend to embed the chart using JavaScript.
	//Embedding using JavaScripts avoids the "Click to Activate..." issue in Internet Explorer
	//When you make your own charts, make sure that the path to this JS file is correct. Else, you would get JavaScript errors.
	?>	
	<script LANGUAGE="Javascript" SRC="../../FusionCharts/FusionCharts.js"></SCRIPT>
	<style type="text/css">
	<!--
	body {
		font-family: Arial, Helvetica, sans-serif;
		font-size: 12px;
	}
	.text{
		font-family: Arial, Helvetica, sans-serif;
		font-size: 12px;
	}
	-->
	</style>
</HEAD>
<BODY>

<CENTER>
<h2><a href="http://www.fusioncharts.com" target="_blank">FusionCharts Free</a> -Database and Drill-Down Example</h2>


<?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 graph element
	$strXML = "<graph hovercapbg='DEDEBE' 
				  	hovercapborder='889E6D' 
				  	yAxisMaxValue='100' 
				  	numdivlines='9' 
				  	divLineColor='CCCCCC' 
				  	divLineAlpha='80' 
				  	decimalPrecision='0' 
				  	showAlternateHGridColor='1' 
				  	AlternateHGridAlpha='30' 
				  	AlternateHGridColor='CCCCCC'
				  	caption = 'Monthly Approvals'>";

	// Fetch all factory records
	$strQuery = "select * from testing";
	
	$result = mysql_query($strQuery) or die(mysql_error());
    
	//Iterate through each factory
	if ($result) {
		while($ors = mysql_fetch_array($result)) {
			//Now create a second query to get details for this factory
			$strQuery = "select COUNT(Result) AS Approved FROM testing WHERE Result = 'Approved'";
			//$strQuery = "select sum(Quantity) as TotOutput from factory_output where FactoryId=" . $ors['FactoryId'];
			$result2 = mysql_query($strQuery) or die(mysql_error()); 
			$ors2 = mysql_fetch_array($result2);
			//Generate <set name='..' value='..' />        
			$strXML .= "<set name='" . $ors['Result'] . "' value='" . $ors2['Approved'] . "' />";
			//free the resultset
			mysql_free_result($result2);
		}
	}
	mysql_close($link);

	//Finally, close <graph> element
	$strXML .= "</graph>";
	
	//Create the chart - Pie 3D Chart with data from $strXML
	echo renderChart("../../FusionCharts/FCF_Column3D.swf", "", $strXML, "Fusion", 650, 450);
?>
<BR><BR>
<a href='../NoChart.html' target="_blank">Unable to see the chart above?</a>
<H5 ><a href='../default.htm'>&laquo; Back to list of examples</a></h5>
</CENTER>
</BODY>
</HTML>




#2 Sashibhusan

Sashibhusan

    Supreme Being

  • Members
  • PipPipPipPipPipPipPipPip
  • 568 posts

Posted 14 May 2012 - 09:52 AM

Hi,

Could you please confirm once that all the files included in your code are having correct relative path and all the files are present physically in the corresponding folders of the path specified?

If not then do changes accordingly and try once again.

Awaiting your response!

#3 DJ-DOO

DJ-DOO

    Forum Member

  • Members
  • PipPipPipPip
  • 25 posts

Posted 14 May 2012 - 10:49 AM

Hi,

Could you please confirm once that all the files included in your code are having correct relative path and all the files are present physically in the corresponding folders of the path specified?

If not then do changes accordingly and try once again.

Awaiting your response!


Hi,

Thank you for your speedy response. In order to clear up any confusion with my paths and locations, I have moved all included files (fusioncharts.php, DBConn.php, FusionCharts.js and FCF_Column3D.swf) to the same folder my main php file BasicDBExample.php is contained in... so now my file reads



<?php
//We've included ../Includes/FusionCharts.php and ../Includes/DBConn.php, which contains
//functions to help us easily embed the charts and connect to a database.
include 'FusionCharts.php';    //CHANGED HERE
include 'DBConn.php';      	//CHANGED HERE
?>
<HTML>
<HEAD>
	<TITLE>
	FusionCharts Free - Database Example
	</TITLE>
	<?php
	//You need to include the following JS file, if you intend to embed the chart using JavaScript.
	//Embedding using JavaScripts avoids the "Click to Activate..." issue in Internet Explorer
	//When you make your own charts, make sure that the path to this JS file is correct. Else, you would get JavaScript errors.
	?>	
	<script type="text/javascript" src="FusionCharts.js"></SCRIPT> //CHANGED HERE
	<style type="text/css">
	<!--
	body {
		font-family: Arial, Helvetica, sans-serif;
		font-size: 12px;
	}
	.text{
		font-family: Arial, Helvetica, sans-serif;
		font-size: 12px;
	}
	-->
	</style>
</HEAD>
<B

<CENTER>
<h2><a href="http://www.fusioncharts.com" target="_blank">FusionCharts Free</a> -Database and Drill-Down Example</h2>


<?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 graph element
	$strXML = "<graph hovercapbg='DEDEBE' 
			  		hovercapborder='889E6D' 
			  		yAxisMaxValue='100' 
			  		numdivlines='9' 
			  		divLineColor='CCCCCC' 
			  		divLineAlpha='80' 
			  		decimalPrecision='0' 
			  		showAlternateHGridColor='1' 
			  		AlternateHGridAlpha='30' 
			  		AlternateHGridColor='CCCCCC'
			  		caption = 'Monthly Approvals'>";

	// Fetch all factory records
	$strQuery = "select * from testing";
	
	$result = mysql_query($strQuery) or die(mysql_error());
    
	//Iterate through each factory
	if ($result) {
		while($ors = mysql_fetch_array($result)) {
			//Now create a second query to get details for this factory
			$strQuery = "select COUNT(Result) AS Approved FROM testing WHERE Result = 'Approved'";
			//$strQuery = "select sum(Quantity) as TotOutput from factory_output where FactoryId=" . $ors['FactoryId'];
			$result2 = mysql_query($strQuery) or die(mysql_error()); 
			$ors2 = mysql_fetch_array($result2);
			//Generate <set name='..' value='..' />        
			$strXML .= "<set name='" . $ors['Result'] . "' value='" . $ors2['Approved'] . "' />";
			//free the resultset
			mysql_free_result($result2);
		}
	}
	mysql_close($link);

	//Finally, close <graph> element
	$strXML .= "</graph>";
	
	//Create the chart - Pie 3D Chart with data from $strXML
	echo renderChart("FCF_Column3D.swf", "", $strXML, "Fusion", 650, 450); //CHANGED HERE
?>
<BR><BR>
<a href='../NoChart.html' target="_blank">Unable to see the chart above?</a>
<H5 ><a href='../default.htm'>&laquo; Back to list of examples</a></h5>
</CENTER>
</BODY>
</HTML>

Unfortunately there is still no chart displaying...

I am sure this is a simple mistake to remedy, I appreciate any help you can give.

Regards,
Gary

#4 Sashibhusan

Sashibhusan

    Supreme Being

  • Members
  • PipPipPipPipPipPipPipPip
  • 568 posts

Posted 14 May 2012 - 12:12 PM

Hey,

Could you please try using the modified code appended below:

<?php
//We've included ../Includes/FusionCharts.php and ../Includes/DBConn.php, which contains
//functions to help us easily embed the charts and connect to a database.
include 'FusionCharts.php';    //CHANGED HERE
include 'DBConn.php';           //CHANGED HERE
?>
<HTML>
<HEAD>
        <TITLE>
        FusionCharts Free - Database Example
        </TITLE>
        <?php
        //You need to include the following JS file, if you intend to embed the chart using JavaScript.
        //Embedding using JavaScripts avoids the "Click to Activate..." issue in Internet Explorer
        //When you make your own charts, make sure that the path to this JS file is correct. Else, you would get JavaScript errors.
        ?>      
        <script type="text/javascript" src="FusionCharts.js"></SCRIPT> //CHANGED HERE
        <style type="text/css">
        <!--
        body {
                font-family: Arial, Helvetica, sans-serif;
                font-size: 12px;
        }
        .text{
                font-family: Arial, Helvetica, sans-serif;
                font-size: 12px;
        }
        -->
        </style>
</HEAD>
<B

<CENTER>
<h2><a href="http://www.fusioncharts.com" target="_blank">FusionCharts Free</a> -Database and Drill-Down Example</h2>


<?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 graph element
       $strXML = "<graph hovercapbg='DEDEBE' hovercapborder='889E6D' yAxisMaxValue='100' numdivlines='9' divLineColor='CCCCCC' divLineAlpha='80' decimalPrecision='0' showAlternateHGridColor='1' AlternateHGridAlpha='30' AlternateHGridColor='CCCCCC' caption = 'Monthly Approvals'>";

        // Fetch all factory records
        $strQuery = "select * from testing";
        
        $result = mysql_query($strQuery) or die(mysql_error());
    
        //Iterate through each factory
        if ($result) {
                while($ors = mysql_fetch_array($result)) {
                        //Now create a second query to get details for this factory
                        $strQuery = "select COUNT(Result) AS Approved FROM testing WHERE Result = 'Approved'";
                        //$strQuery = "select sum(Quantity) as TotOutput from factory_output where FactoryId=" . $ors['FactoryId'];
                        $result2 = mysql_query($strQuery) or die(mysql_error()); 
                        $ors2 = mysql_fetch_array($result2);
                        //Generate <set name='..' value='..' />        
                        $strXML .= "<set name='" . $ors['Result'] . "' value='" . $ors2['Approved'] . "' />";
                        //free the resultset
                        mysql_free_result($result2);
                }
        }
        mysql_close($link);

        //Finally, close <graph> element
        $strXML .= "</graph>";
        
        //Create the chart - Pie 3D Chart with data from $strXML
        echo renderChart("FCF_Column3D.swf", "", $strXML, "Fusion", 650, 450); //CHANGED HERE
?>
<BR><BR>
<a href='../NoChart.html' target="_blank">Unable to see the chart above?</a>
<H5 ><a href='../default.htm'>&laquo; Back to list of examples</a></h5>
</CENTER>
</BODY>
</HTML>

Please note that including of new-line characters in the XML/JSON string cause JavaScript error which results in displaying "Chart" in stead of rendering the chart.

Hope this helps!

#5 DJ-DOO

DJ-DOO

    Forum Member

  • Members
  • PipPipPipPip
  • 25 posts

Posted 14 May 2012 - 01:07 PM

Hey,

Could you please try using the modified code appended below:

<?php
//We've included ../Includes/FusionCharts.php and ../Includes/DBConn.php, which contains
//functions to help us easily embed the charts and connect to a database.
include 'FusionCharts.php';    //CHANGED HERE
include 'DBConn.php';       	//CHANGED HERE
?>
<HTML>
<HEAD>
        <TITLE>
        FusionCharts Free - Database Example
        </TITLE>
        <?php
        //You need to include the following JS file, if you intend to embed the chart using JavaScript.
        //Embedding using JavaScripts avoids the "Click to Activate..." issue in Internet Explorer
        //When you make your own charts, make sure that the path to this JS file is correct. Else, you would get JavaScript errors.
        ?>      
        <script type="text/javascript" src="FusionCharts.js"></SCRIPT> //CHANGED HERE
        <style type="text/css">
        <!--
        body {
                font-family: Arial, Helvetica, sans-serif;
                font-size: 12px;
        }
        .text{
                font-family: Arial, Helvetica, sans-serif;
                font-size: 12px;
        }
        -->
        </style>
</HEAD>
<B

<CENTER>
<h2><a href="http://www.fusioncharts.com" target="_blank">FusionCharts Free</a> -Database and Drill-Down Example</h2>


<?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 graph element
   	$strXML = "<graph hovercapbg='DEDEBE' hovercapborder='889E6D' yAxisMaxValue='100' numdivlines='9' divLineColor='CCCCCC' divLineAlpha='80' decimalPrecision='0' showAlternateHGridColor='1' AlternateHGridAlpha='30' AlternateHGridColor='CCCCCC' caption = 'Monthly Approvals'>";

        // Fetch all factory records
        $strQuery = "select * from testing";
        
        $result = mysql_query($strQuery) or die(mysql_error());
    
        //Iterate through each factory
        if ($result) {
                while($ors = mysql_fetch_array($result)) {
                        //Now create a second query to get details for this factory
                        $strQuery = "select COUNT(Result) AS Approved FROM testing WHERE Result = 'Approved'";
                        //$strQuery = "select sum(Quantity) as TotOutput from factory_output where FactoryId=" . $ors['FactoryId'];
                        $result2 = mysql_query($strQuery) or die(mysql_error()); 
                        $ors2 = mysql_fetch_array($result2);
                        //Generate <set name='..' value='..' />        
                        $strXML .= "<set name='" . $ors['Result'] . "' value='" . $ors2['Approved'] . "' />";
                        //free the resultset
                        mysql_free_result($result2);
                }
        }
        mysql_close($link);

        //Finally, close <graph> element
        $strXML .= "</graph>";
        
        //Create the chart - Pie 3D Chart with data from $strXML
        echo renderChart("FCF_Column3D.swf", "", $strXML, "Fusion", 650, 450); //CHANGED HERE
?>
<BR><BR>
<a href='../NoChart.html' target="_blank">Unable to see the chart above?</a>
<H5 ><a href='../default.htm'>&laquo; Back to list of examples</a></h5>
</CENTER>
</BODY>
</HTML>

Please note that including of new-line characters in the XML/JSON string cause JavaScript error which results in displaying "Chart" in stead of rendering the chart.

Hope this helps!


Thank you very much!!! A chart is displaying!! Now I just need to edit it and my sql to produce the results I want.

#6 DJ-DOO

DJ-DOO

    Forum Member

  • Members
  • PipPipPipPip
  • 25 posts

Posted 14 May 2012 - 02:23 PM

Hey,

Could you please try using the modified code appended below:

<?php
//We've included ../Includes/FusionCharts.php and ../Includes/DBConn.php, which contains
//functions to help us easily embed the charts and connect to a database.
include 'FusionCharts.php';    //CHANGED HERE
include 'DBConn.php';   		//CHANGED HERE
?>
<HTML>
<HEAD>
        <TITLE>
        FusionCharts Free - Database Example
        </TITLE>
        <?php
        //You need to include the following JS file, if you intend to embed the chart using JavaScript.
        //Embedding using JavaScripts avoids the "Click to Activate..." issue in Internet Explorer
        //When you make your own charts, make sure that the path to this JS file is correct. Else, you would get JavaScript errors.
        ?>      
        <script type="text/javascript" src="FusionCharts.js"></SCRIPT> //CHANGED HERE
        <style type="text/css">
        <!--
        body {
                font-family: Arial, Helvetica, sans-serif;
                font-size: 12px;
        }
        .text{
                font-family: Arial, Helvetica, sans-serif;
                font-size: 12px;
        }
        -->
        </style>
</HEAD>
<B

<CENTER>
<h2><a href="http://www.fusioncharts.com" target="_blank">FusionCharts Free</a> -Database and Drill-Down Example</h2>


<?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 graph element
   	$strXML = "<graph hovercapbg='DEDEBE' hovercapborder='889E6D' yAxisMaxValue='100' numdivlines='9' divLineColor='CCCCCC' divLineAlpha='80' decimalPrecision='0' showAlternateHGridColor='1' AlternateHGridAlpha='30' AlternateHGridColor='CCCCCC' caption = 'Monthly Approvals'>";

        // Fetch all factory records
        $strQuery = "select * from testing";
        
        $result = mysql_query($strQuery) or die(mysql_error());
    
        //Iterate through each factory
        if ($result) {
                while($ors = mysql_fetch_array($result)) {
                        //Now create a second query to get details for this factory
                        $strQuery = "select COUNT(Result) AS Approved FROM testing WHERE Result = 'Approved'";
                        //$strQuery = "select sum(Quantity) as TotOutput from factory_output where FactoryId=" . $ors['FactoryId'];
                        $result2 = mysql_query($strQuery) or die(mysql_error()); 
                        $ors2 = mysql_fetch_array($result2);
                        //Generate <set name='..' value='..' />        
                        $strXML .= "<set name='" . $ors['Result'] . "' value='" . $ors2['Approved'] . "' />";
                        //free the resultset
                        mysql_free_result($result2);
                }
        }
        mysql_close($link);

        //Finally, close <graph> element
        $strXML .= "</graph>";
        
        //Create the chart - Pie 3D Chart with data from $strXML
        echo renderChart("FCF_Column3D.swf", "", $strXML, "Fusion", 650, 450); //CHANGED HERE
?>
<BR><BR>
<a href='../NoChart.html' target="_blank">Unable to see the chart above?</a>
<H5 ><a href='../default.htm'>&laquo; Back to list of examples</a></h5>
</CENTER>
</BODY>
</HTML>

Please note that including of new-line characters in the XML/JSON string cause JavaScript error which results in displaying "Chart" in stead of rendering the chart.

Hope this helps!



Thank you for your help thus far!!! I'm just wondering if I want to display the months along the x axis, I can't do it as explained in the samples as it's xml within php, I keep getting xml errors...
I imagine it is something like this?
//Generate <set name='..' value='..' />         
$strXML .= "<set name='" . 'Jan' . "' value='" . $ors2['Approved'] . "'color='F6BD0F'/> <set name'" . 'Feb' . "' value='" . $ors2['Approved'] . "'color='F6BD0F' />";                     
//free the resultset
mysql_free_result($result2);



Apologies for the silly questions, it's just that it's so new and I'm a 2nd year student.

Regards,
Gary

#7 DJ-DOO

DJ-DOO

    Forum Member

  • Members
  • PipPipPipPip
  • 25 posts

Posted 15 May 2012 - 09:28 AM

Anyone??

I tried passing the xml into a php variable and loading that variable into $strXML using simplexml_load_string but to no avail




$xmlData =<<< END
<?xml version = "1.0"?>

<graph xaxisname= "Export" bgColor = "FFFFFF" hovercapborder="889E6D" rorateNames ="0" yAxisMaxValue="100" numdivlines="9"  divLineColor="CCCCCC" divLineAlpha="80" decimalPrecision="0" showAlternateHGridColor="1" AlternateHGridAlpha="30" AlternateHGridColor="CCCCCC" caption = "Monthly Approvals">
	<categories font="Arial" fontSize ="11" fontColor ="000000">
  	<category name ="Jan" hoverText ="January"/>
  	<category name ="Feb" hoverText ="February"/>
  	<category name ="Mar" hoverText ="March"/>
  	<category name ="Apr" hoverText ="April"/>
  	<category name ="May" hoverText ="May"/>
  	<category name ="Jun" hoverText ="June"/>
  	<category name ="Jul" hoverText ="July"/>
  	<category name ="Aug" hoverText ="August"/>
  	<category name ="Sept" hoverText ="September"/>
  	<category name ="Oct" hoverText ="October"/>
  	<category name ="Nov" hoverText ="November"/>
  	<category name ="Dec" hoverText ="December"/>
	</categories>
</graph>
END;

$strXML = simplexml_load_string($xmlData) or die("Error: Cannot Create Object");

However, when I do this I just get "chart" instead of the actual chart. If anyone could give me an idea how to do this I would be extremely grateful. I do understand that this is more than likely simple to fix, however, it's only simple when you know how...and unfortunately, I don't...I've been trying here for a day now and no joy...

#8 Sashibhusan

Sashibhusan

    Supreme Being

  • Members
  • PipPipPipPipPipPipPipPip
  • 568 posts

Posted 15 May 2012 - 10:09 AM

Hey,

As I have already mentioned in the previous post that the "new line character" will cause JavaScript error in XML string and hence results in showing "Chart" instead of actual chart,

Could you please build the XML string by removing the "new line characters"?

Correct Code:
$xmlData =<<< END
<?xml version = "1.0"?>
<graph xaxisname= "Export" bgColor = "FFFFFF" hovercapborder="889E6D" rorateNames ="0" yAxisMaxValue="100" numdivlines="9"  divLineColor="CCCCCC" divLineAlpha="80" decimalPrecision="0" showAlternateHGridColor="1" AlternateHGridAlpha="30" AlternateHGridColor="CCCCCC" caption = "Monthly Approvals"><categories font="Arial" fontSize ="11" fontColor ="000000"><category name ="Jan" hoverText ="January"/><category name ="Feb" hoverText ="February"/><category name ="Mar" hoverText ="March"/><category name ="Apr" hoverText ="April"/><category name ="May" hoverText ="May"/><category name ="Jun" hoverText ="June"/><category name ="Jul" hoverText ="July"/><category name ="Aug" hoverText ="August"/><category name ="Sept" hoverText ="September"/><category name ="Oct" hoverText ="October"/><category name ="Nov" hoverText ="November"/><category name ="Dec" hoverText ="December"/></categories></graph>
END;
$strXML = simplexml_load_string($xmlData) or die("Error: Cannot Create Object");

Hope this helps!

#9 DJ-DOO

DJ-DOO

    Forum Member

  • Members
  • PipPipPipPip
  • 25 posts

Posted 15 May 2012 - 10:31 AM

Hey,

As I have already mentioned in the previous post that the "new line character" will cause JavaScript error in XML string and hence results in showing "Chart" instead of actual chart,

Could you please build the XML string by removing the "new line characters"?

Correct Code:

$xmlData =<<< END
<?xml version = "1.0"?>
<graph xaxisname= "Export" bgColor = "FFFFFF" hovercapborder="889E6D" rorateNames ="0" yAxisMaxValue="100" numdivlines="9"  divLineColor="CCCCCC" divLineAlpha="80" decimalPrecision="0" showAlternateHGridColor="1" AlternateHGridAlpha="30" AlternateHGridColor="CCCCCC" caption = "Monthly Approvals"><categories font="Arial" fontSize ="11" fontColor ="000000"><category name ="Jan" hoverText ="January"/><category name ="Feb" hoverText ="February"/><category name ="Mar" hoverText ="March"/><category name ="Apr" hoverText ="April"/><category name ="May" hoverText ="May"/><category name ="Jun" hoverText ="June"/><category name ="Jul" hoverText ="July"/><category name ="Aug" hoverText ="August"/><category name ="Sept" hoverText ="September"/><category name ="Oct" hoverText ="October"/><category name ="Nov" hoverText ="November"/><category name ="Dec" hoverText ="December"/></categories></graph>
END;
$strXML = simplexml_load_string($xmlData) or die("Error: Cannot Create Object");

Hope this helps!


Apologies for creating a similar error and thank you for your help.

Unfortunately, I am not getting 'Invalid XML Data' instead of a chart...

I'm unsure now as what I've done wrong Posted Image

#10 Sashibhusan

Sashibhusan

    Supreme Being

  • Members
  • PipPipPipPipPipPipPipPip
  • 568 posts

Posted 15 May 2012 - 11:35 AM

Hey,

The "Invalid XML Data" error you will get only when the XML data provided to the chart is malformed.

In your case you are providing the XML in the format for Multiseries Charts (as <categories> are inserted) and if you are rendering the single series chart (FCF_Column3D.SWF) then, the above error will be thrown.

So could you please include the MultiSeries Chart SWF file in your application and include the same in your code?

Please find the modified code appended below, where the X-Axis will show the months name and the Y-Axis plot the Count(result) grouped by month.

Code:
<?php
include 'FusionCharts.php';
include 'DBConn.php';
?>
<HTML>
<HEAD>
    	<TITLE>
    	FusionCharts Free - Database Example
    	</TITLE>
    	<?php
    	?>  	
    	<script type="text/javascript" src="FusionCharts.js"></SCRIPT>
    	<style type="text/css">
    	<!--
    	body {
            	font-family: Arial, Helvetica, sans-serif;
            	font-size: 12px;
    	}
    	.text{
            	font-family: Arial, Helvetica, sans-serif;
            	font-size: 12px;
    	}
    	-->
    	</style>
</HEAD>
<BODY>

<CENTER>
<h2><a href="http://www.fusioncharts.com" target="_blank">FusionCharts Free</a> -Database and Drill-Down Example</h2>


<?php
    	$link = connectToDB();
    	$strXML = "<graph hovercapbg='DEDEBE' hovercapborder='889E6D' yAxisMaxValue='100' numdivlines='9' divLineColor='CCCCCC' divLineAlpha='80' decimalPrecision='0' showAlternateHGridColor='1' AlternateHGridAlpha='30' AlternateHGridColor='CCCCCC' caption = 'Monthly Approvals'><categories><category name='Jan' hoverText='January'/><category name='Feb' hoverText='February'/><category name='Mar' hoverText='March'/><category name='Apr' hoverText='April'/><category name='May' hoverText='May'/><category name='Jun' hoverText='June'/><category name='Jul' hoverText='January'/><category name='Aug' hoverText='February'/><category name='Sept' hoverText='March'/><category name='Oct' hoverText='April'/><category name='Nov' hoverText='May'/><category name='Dec' hoverText='June'/></categories>";
		$strXML .= "<dataset>";
    	$strQuery = "select * from testing";
    	$result = mysql_query($strQuery) or die(mysql_error());
    	if ($result) {
            	while($ors = mysql_fetch_array($result)) {
                    	$strQuery = "select COUNT(Result) AS Approved FROM testing WHERE Result = 'Approved' GROUP By MONTH(Date) ASC";
                    	$result2 = mysql_query($strQuery) or die(mysql_error()); 
                    	$ors2 = mysql_fetch_array($result2);
                    	$strXML .= "<set value='" . $ors2['Approved'] . "' />";
                    	mysql_free_result($result2);
            	}
    	}
    	mysql_close($link);
		$strXML .= "</dataset>";
    	$strXML .= "</graph>";
    	echo renderChart("FCF_MSColumn3D.swf", "", $strXML, "Fusion", 650, 450);
?>
<BR><BR>
<a href='../NoChart.html' target="_blank">Unable to see the chart above?</a>
<H5 ><a href='../default.htm'>&laquo; Back to list of examples</a></h5>
</CENTER>
</BODY>
</HTML>

Note: Before rendering the chart please make sure all the SQL query would results correct data from the database.

Hope this helps!

#11 DJ-DOO

DJ-DOO

    Forum Member

  • Members
  • PipPipPipPip
  • 25 posts

Posted 22 May 2012 - 08:22 AM

Thank you so much for your help, this has really helped me get a better understanding!!! One more quick question, I'm trying to use multiple charts on the same page. I've looked at your example on how to do this, however, it's the same issue, it's all html...I've been trying here, and uploading, and editing and uploading but with no success and now I'm pulling my hair out!!

If I could get one last pointer on this I would be very very grateful


Regards,

Gary

Edited by DJ-DOO, 22 May 2012 - 08:30 AM.


#12 DJ-DOO

DJ-DOO

    Forum Member

  • Members
  • PipPipPipPip
  • 25 posts

Posted 22 May 2012 - 10:47 AM

Thank you so much for your help, this has really helped me get a better understanding!!! One more quick question, I'm trying to use multiple charts on the same page. I've looked at your example on how to do this, however, it's the same issue, it's all html...I've been trying here, and uploading, and editing and uploading but with no success and now I'm pulling my hair out!!

If I could get one last pointer on this I would be very very grateful


Regards,

Gary


Anyone?? I'm at my wits end here, this has to be done, however, I'm unsure as to how do it or if it is even possible!!

Any help would be so appreciated as I'm learning as I go!

Regards,
Gary

#13 Sashibhusan

Sashibhusan

    Supreme Being

  • Members
  • PipPipPipPipPipPipPipPip
  • 568 posts

Posted 22 May 2012 - 11:18 AM

Hi,

Thank you for the post.

For creating multiple charts in a single page using PHP and MySQL database, you need to invoke the FusionCharts JavaScript function "renderChart();" multiple times along with the necessary arguments.

Below mentioned reference code is used for rendering Column3D, Column2D and Line graphs with the same XML data in a single page.

If you want to plot different values, you can form the strXML for the each chart same as the code below.

Ref. Code:
<?php
include 'FusionCharts.php';
include 'DBConn.php';
?>
<HTML>
<HEAD>
        <TITLE>
        FusionCharts Free - Database Example
        </TITLE>
        <?php
        ?>      
        <script type="text/javascript" src="FusionCharts.js"></SCRIPT>
        <style type="text/css">
        <!--
        body {
                font-family: Arial, Helvetica, sans-serif;
                font-size: 12px;
        }
        .text{
                font-family: Arial, Helvetica, sans-serif;
                font-size: 12px;
        }
        -->
        </style>
</HEAD>
<BODY>

<CENTER>
<h2><a href="http://www.fusioncharts.com" target="_blank">FusionCharts Free</a> -Database and Drill-Down Example</h2>


<?php
        $link = connectToDB();
        $strXML = "<graph hovercapbg='DEDEBE' hovercapborder='889E6D' yAxisMaxValue='100' numdivlines='9' divLineColor='CCCCCC' divLineAlpha='80' decimalPrecision='0' showAlternateHGridColor='1' AlternateHGridAlpha='30' AlternateHGridColor='CCCCCC' caption = 'Monthly Approvals'><categories><category name='Jan' hoverText='January'/><category name='Feb' hoverText='February'/><category name='Mar' hoverText='March'/><category name='Apr' hoverText='April'/><category name='May' hoverText='May'/><category name='Jun' hoverText='June'/><category name='Jul' hoverText='January'/><category name='Aug' hoverText='February'/><category name='Sept' hoverText='March'/><category name='Oct' hoverText='April'/><category name='Nov' hoverText='May'/><category name='Dec' hoverText='June'/></categories>";
                $strXML .= "<dataset>";
        $strQuery = "select * from testing";
        $result = mysql_query($strQuery) or die(mysql_error());
        if ($result) {
                while($ors = mysql_fetch_array($result)) {
                        $strQuery = "select COUNT(Result) AS Approved FROM testing WHERE Result = 'Approved' GROUP By MONTH(Date) ASC";
                        $result2 = mysql_query($strQuery) or die(mysql_error()); 
                        $ors2 = mysql_fetch_array($result2);
                        $strXML .= "<set value='" . $ors2['Approved'] . "' />";
                        mysql_free_result($result2);
                }
        }
        mysql_close($link);
                $strXML .= "</dataset>";
        $strXML .= "</graph>";
        echo renderChart("FCF_MSColumn3D.swf", "", $strXML, "Fusion1", 650, 450);
        
        echo renderChart("FCF_MSColumn2D.swf", "", $strXML, "Fusion2", 650, 450); 
        echo renderChart("FCF_MSLine.swf", "", $strXML, "Fusion3", 650, 450); 
?>
<BR><BR>
<a href='../NoChart.html' target="_blank">Unable to see the chart above?</a>
<H5 ><a href='../default.htm'>&laquo; Back to list of examples</a></h5>
</CENTER>
</BODY>
</HTML>

Hope this helps!

#14 DJ-DOO

DJ-DOO

    Forum Member

  • Members
  • PipPipPipPip
  • 25 posts

Posted 07 June 2012 - 11:32 AM

Hi!

I'm back unfortunately with a similar issue, so rather than starting a new thread I thought it might be best to continue on this thread. I am currently developing an internal tool for the company I am doing my internship with. On the dashboard of this tool it is required for me to chart dynamic data. For testing purposes I have charted static data with an external xml file which is no problem. I have three multi series charts, and two pie charts. However, now, when it comes to charting it dynamically I'm somewhat lost. The multi series charts have three legends 'Approved', 'Unapproved' and 'Cancelled'. I have a number of forums, so I need to chart the amount of approved, unapproved and cancelled by forum. I have my database query which gives me the required results, I'm just unsure as to how to implement it into a fusion chart.

The query I have is:
SELECT review.reviewForum
 	, COUNT(CASE WHEN mom.result = 'Approved'
                  THEN 'yes' ELSE NULL END) AS Approved
 	, COUNT(CASE WHEN mom.result = 'NOT Approved'
                  THEN 'yes' ELSE NULL END) AS Not_Approved
 	, COUNT(CASE WHEN mom.result = 'Cancelled'
                  THEN 'yes' ELSE NULL END) AS Cancelled
  FROM review
INNER
  JOIN mom
    ON mom.reviewId = review.reviewId 
GROUP
    BY review.reviewForum


This produces :
reviewForum 	APPROVED    NOT_APPROVED   CANCELLED
A                    2            1            0
B                    5            3            3 
C                    2            1            2  
D                    2            2            9  
E                    2            8            1  
F                    2            6            5
G                    2            1            1  

What I ultimately need to do is have approved, not_approved and cancelled as the series, then on the x axis have my forums. I know there are people that might think I'm lazy, I can assure those that this isn't the case, I'm a student trying to learn and figure out how to do this, unfortunately I have deadlines in my internship and I need some help in order to meet those deadlines.

If there is anyone that can help me out here, I would really really appreciate it.

On an aside I've researched that you can tranform mysql query results into xml, could this be an option for fusion charts??

Regards,
Gary

#15 DJ-DOO

DJ-DOO

    Forum Member

  • Members
  • PipPipPipPip
  • 25 posts

Posted 07 June 2012 - 03:09 PM

This is my effort thus far, it's not working, it is displaying 'chart' so therefore I have an xml error..can anyone help please??

	$strXML = "<graph hovercapbg='DEDEBE' hovercapborder='889E6D' yAxisMaxValue='20' numdivlines='4' divLineColor='CCCCCC' divLineAlpha='80' decimalPrecision='0' showAlternateHGridColor='1' AlternateHGridAlpha='30' AlternateHGridColor='CCCCCC' caption = 'Forum Status'><categories><category name='TC OSS RC' hoverText='TC OSS RC'/><category name='TC PM' hoverText='TC PM'/><category name='TC TOR' hoverText='TC TOR'/><category name='TC PF' hoverText='TC PF'/><category name='TC WRAN' hoverText='TC WRAN'/><category name='TC GRAN' hoverText='TC GRAN'/><category name='TC CNOSS' hoverText='TC CNOSS'/><category name='TC OSS Arch Board' hoverText='TC OSS Arch Board'/></categories>";
 		$strXML .= "<dataset seriesname = 'Approved' , seriesname = 'Unapproved', series name='Cancelled'>";
      
      
                        $strQuery = "SELECT review.reviewForum	, COUNT(CASE WHEN mom.result = 'Approved' THEN 'yes' ELSE NULL END) AS Approved , COUNT(CASE WHEN mom.result = 'NOT Approved' THEN 'yes' ELSE NULL END) AS Not_Approved , COUNT(CASE WHEN mom.result = 'Cancelled' THEN 'yes' ELSE NULL END) AS Cancelled FROM review INNER	JOIN mom ON mom.reviewId = review.reviewId GROUP BY review.reviewForum";
                        $result2 = mysql_query($strQuery) or die(mysql_error()); 
                        $ors = mysql_fetch_array($result2);
                        $strXML .= "<set value='" . $ors['Approved'] . $ors ['Not_Approved'] . $ors['Cancelled'] . "' />";
                        mysql_free_result($result2);

                $strXML .= "</dataset>";
        $strXML .= "</graph>";
             	
        echo renderChart("FCF_MSColumn2D.swf", "", $strXML, "Fusion2", 400, 200);

Edited by DJ-DOO, 07 June 2012 - 03:22 PM.


#16 Sumedh

Sumedh

    Supreme Being

  • Administrators
  • 1949 posts
  • LocationBangalore

Posted 08 June 2012 - 09:21 AM

This is my effort thus far, it's not working, it is displaying 'chart' so therefore I have an xml error..can anyone help please??

	$strXML = "<graph hovercapbg='DEDEBE' hovercapborder='889E6D' yAxisMaxValue='20' numdivlines='4' divLineColor='CCCCCC' divLineAlpha='80' decimalPrecision='0' showAlternateHGridColor='1' AlternateHGridAlpha='30' AlternateHGridColor='CCCCCC' caption = 'Forum Status'><categories><category name='TC OSS RC' hoverText='TC OSS RC'/><category name='TC PM' hoverText='TC PM'/><category name='TC TOR' hoverText='TC TOR'/><category name='TC PF' hoverText='TC PF'/><category name='TC WRAN' hoverText='TC WRAN'/><category name='TC GRAN' hoverText='TC GRAN'/><category name='TC CNOSS' hoverText='TC CNOSS'/><category name='TC OSS Arch Board' hoverText='TC OSS Arch Board'/></categories>";
 		$strXML .= "<dataset seriesname = 'Approved' , seriesname = 'Unapproved', series name='Cancelled'>";
      
      
                        $strQuery = "SELECT review.reviewForum	, COUNT(CASE WHEN mom.result = 'Approved' THEN 'yes' ELSE NULL END) AS Approved , COUNT(CASE WHEN mom.result = 'NOT Approved' THEN 'yes' ELSE NULL END) AS Not_Approved , COUNT(CASE WHEN mom.result = 'Cancelled' THEN 'yes' ELSE NULL END) AS Cancelled FROM review INNER	JOIN mom ON mom.reviewId = review.reviewId GROUP BY review.reviewForum";
                        $result2 = mysql_query($strQuery) or die(mysql_error()); 
                        $ors = mysql_fetch_array($result2);
                        $strXML .= "<set value='" . $ors['Approved'] . $ors ['Not_Approved'] . $ors['Cancelled'] . "' />";
                        mysql_free_result($result2);

                $strXML .= "</dataset>";
        $strXML .= "</graph>";
         		
        echo renderChart("FCF_MSColumn2D.swf", "", $strXML, "Fusion2", 400, 200);


Hi,

Could you please check if the all the file's paths are specified correctly or not?


Thanks,
Sumedh

Follow us @Twitter!

#17 DJ-DOO

DJ-DOO

    Forum Member

  • Members
  • PipPipPipPip
  • 25 posts

Posted 08 June 2012 - 09:26 AM

Hi,

Could you please check if the all the file's paths are specified correctly or not?


Hi Sumedh,

Yes the paths are correct, I have the php file and the charts within the same directory in order to avoid any confusion with paths.

Thank you for your reply.

Regards,

Gary

#18 DJ-DOO

DJ-DOO

    Forum Member

  • Members
  • PipPipPipPip
  • 25 posts

Posted 08 June 2012 - 10:12 AM

It still isn't working unfortunately, would you have any ideas?

Regards,
Gary

#19 Swarnam

Swarnam

    Supreme Being

  • Moderators
  • 727 posts

Posted 09 June 2012 - 02:37 AM

Please refer to the forum post:
http://forum.fusionc...6769#entry46769

#20 HELPmePLEASE

HELPmePLEASE

    Forum Newbie

  • Members
  • 1 posts

Posted 16 July 2012 - 08:29 PM

Hi all,

I have read through these posts looking for an answer to my solution. I have used the code that was working for DJ-DOO as a base for my code. I moved all of the files included FusionCharts, DBConn, and so on into the same folder as my file BasicDBExample. This is just in the DB Example folder I created in my Home directory. When I run it I get nothing. No Chart and No chart displaying. I'm not sure why it is not working.




<?php
//We've included ../Includes/FusionCharts.php and ../Includes/DBConn.php, which contains
//functions to help us easily embed the charts and connect to a database.
include 'FusionCharts.php';	//CHANGED HERE
include 'DBConn.php';   		//CHANGED HERE
?>
<HTML>
<HEAD>
    	<TITLE>
    	FusionCharts Free - Database Example
    	</TITLE>
    	<?php
    	//You need to include the following JS file, if you intend to embed the chart using JavaScript.
    	//Embedding using JavaScripts avoids the "Click to Activate..." issue in Internet Explorer
    	//When you make your own charts, make sure that the path to this JS file is correct. Else, you would get JavaScript errors.
    	?>  	
    	<script type="text/javascript" src="FusionCharts.js"></SCRIPT> //CHANGED HERE
    	<style type="text/css">
    	<!--
    	body {
            	font-family: Arial, Helvetica, sans-serif;
            	font-size: 12px;
    	}
    	.text{
            	font-family: Arial, Helvetica, sans-serif;
            	font-size: 12px;
    	}
    	-->
    	</style>
</HEAD>
<B

<CENTER>
<h2><a href="http://www.fusioncharts.com" target="_blank">FusionCharts Free</a> -Database and Drill-Down Example</h2>


<?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 graph element
   	$strXML = "<graph hovercapbg='DEDEBE' hovercapborder='889E6D' yAxisMaxValue='100' numdivlines='9' divLineColor='CCCCCC' divLineAlpha='80' decimalPrecision='0' showAlternateHGridColor='1' AlternateHGridAlpha='30' AlternateHGridColor='CCCCCC' caption = 'Monthly Approvals'>";

    	// Fetch all factory records
    	$strQuery = "select * from AppData";
    	
    	$result = mysql_query($strQuery) or die(mysql_error());
	
    	//Iterate through each factory
    	if ($result) {
            	while($ors = mysql_fetch_array($result)) {
                    	//Now create a second query to get details for this factory
                    	$strQuery = "select COUNT(AppName)FROM AppData WHERE AppName = 'Calculator'";
                    	//$strQuery = "select sum(Quantity) as TotOutput from factory_output where FactoryId=" . $ors['FactoryId'];
                    	$result2 = mysql_query($strQuery) or die(mysql_error()); 
                    	$ors2 = mysql_fetch_array($result2);
                    	//Generate <set name='..' value='..' />    	
                    	$strXML .= "<set name='" . $ors['AppName'] . "' value='" . $ors2['Calculator'] . "' />";
                    	//free the resultset
                    	mysql_free_result($result2);
            	}
    	}
    	mysql_close($link);

    	//Finally, close <graph> element
    	$strXML .= "</graph>";
    	
    	//Create the chart - Pie 3D Chart with data from $strXML
    	echo renderChart("FCF_Column3D.swf", "", $strXML, "Fusion", 650, 450); //CHANGED HERE
?>
<BR><BR>
<a href='NoChart.html' target="_blank">Unable to see the chart above?</a>
<H5 ><a href='default.htm'>&laquo; Back to list of examples</a></h5>
</CENTER>
</BODY>
</HTML> 


#21 Sashibhusan

Sashibhusan

    Supreme Being

  • Members
  • PipPipPipPipPipPipPipPip
  • 568 posts

Posted 17 July 2012 - 06:04 AM

Hi,

With regard to your query, could you please confirm once again,

1. Whether, you have modified the "DBConn.php" file as per your database connection parameters and "connectToDB()" is establishing a connection to your database successfully?

2. Whether you have copied "FCF_Column3D.swf" file from FusionCharts Free Download pack > Charts folder, along with other files (FusionCharts.js, DBConn.php, FusionCharts.php) to your application folder (DB Example) ?

3. If the above two points you have done correctly then, try echoing $ors['AppName'] and $ors2['Calculator'] to the browser and see if they returns correct data from the database (as per your requirement) ?

Also it seems from your code that you are providing value as $ors2['Calculator'] and "Calculator" is not your return SQL query field name.

So Could you please modify the code as below mentioned and try once?

Ref. Code:
$strQuery = "select * from AppData";
        
        $result = mysql_query($strQuery) or die(mysql_error());
        
        //Iterate through each factory
        if ($result) {
                while($ors = mysql_fetch_array($result)) {
                        //Now create a second query to get details for this factory
                        $strQuery = "select COUNT(AppName) AS AppName_Count FROM AppData WHERE AppName = 'Calculator'";//Modified This line of code
                        //$strQuery = "select sum(Quantity) as TotOutput from factory_output where FactoryId=" . $ors['FactoryId'];
                        $result2 = mysql_query($strQuery) or die(mysql_error()); 
                        $ors2 = mysql_fetch_array($result2);
                        //Generate <set name='..' value='..' />         
                        $strXML .= "<set name='" . $ors['AppName'] . "' value='" . $ors2['AppName_Count'] . "' />";//Modified This line of code
                        //free the resultset
                        mysql_free_result($result2);
                }
        }


Awaiting your valuable response.

Edited by Sashibhusan, 17 July 2012 - 06:10 AM.