Jump to content


How To Use Php And Mysql With Fusioncharts ?


  • Please log in to reply
11 replies to this topic

#1 Jesús

Jesús

    Advanced Member

  • Members
  • PipPipPipPip
  • 50 posts

Posted 24 August 2011 - 10:17 PM

Hi everyone,


I'm trying to generate a graph with data that are stored in a mySQL database.

I read the tutorial titled How Can We use FusionCharts Free with PHP for plotting data from a database? but I could not understand it completely.

So I would like to open this topic to see if somebody can guide me in building a simple linear graph.

My site is structured in a very simple way.

The index is an HTML form where you choose options that make up the query to the database.

This query is executed with the submit button and through the method _POST in PHP.

The query result is what I want bring to the chart.

Someone will have a clear example of how can i plot this result?

#2 Guest_Angshu_*

Guest_Angshu_*
  • Guests

Posted 25 August 2011 - 06:29 AM

Hi,

Welcome to FusionCharts Forum! Posted Image

Please visit the links below :

http://www.fusioncha...sicExample.html

http://www.fusioncha.../?PHP_Form.html

http://www.fusioncha...cs/?PHP_DB.html

Hope this helps.

#3 Jesús

Jesús

    Advanced Member

  • Members
  • PipPipPipPip
  • 50 posts

Posted 25 August 2011 - 09:59 PM

Hi !!

Thanks for your answer, i'll try to use this documentation.

If i dont get the expected results, could i send you my source code ?? in order to receive your opinion or corrections.

Thanks!!

#4 Guest_Angshu_*

Guest_Angshu_*
  • Guests

Posted 26 August 2011 - 06:31 AM

Hi,

Thanks for your response.

You can always send the source code in this forum.

Happy FusionCharting! Posted Image

#5 Jesús

Jesús

    Advanced Member

  • Members
  • PipPipPipPip
  • 50 posts

Posted 26 August 2011 - 07:22 PM

Hi Angshu!!! As you can see i'm new usins this technology.


Well, I had been reading the doumentation that you provide me and I've tried to apply it to my source code.


Unfortunately I have not gotten the desired results, so i want to share with you my source code in order to get your opinion.


The last result that I got in my browser is as follows:


!-- strXML established --!

!-- Data Base connection established --!!-- strQuery established --!SELECT id_fecha AS Fecha, id_fin AS Txns FROM `datos` WHERE id_prod = 'ATM' AND id_ambt = 'NACI' AND 'id_fin' = 'id_fin' AND id_fecha BETWEEN 20110701 AND 20110705!-- result with RESULTS --!Resource id #6

Chart




And this is my source code:


<?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";
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR...nsitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>GRAFINCANDO</title>
<script LANGUAGE="Javascript" SRC="includes/FusionCharts.js"></SCRIPT>
</head>

<body>
<center>

<?php

$qAnio = $_POST['qAnio'];
$qMes = $_POST['qMes'];
$qDia = $_POST['qDia'];
$qAnio2= $_POST['qAnio2'];
$qMes2 = $_POST['qMes2'];
$qDia2 = $_POST['qDia2'];
$qProd = $_POST['qProd'];
$qAmbt = $_POST['qAmbt'];
$qTxn = $_POST['qTxn'];
$qFecha = "$qAnio$qMes$qDia";
$qFecha2= "$qAnio2$qMes2$qDia2";

if ($qTxn == "id_fin") { $TXN = "FINANCIERAS"; }
else {
if ($qTxn == "id_adm") { $TXN = "ADMINISTRATIVAS"; }
else { $TXN = "TOTALES"; }
}

//Generate the chart element string
$strXML = "<chart palette='2' caption='Producto " . $qProd ." Output ' subcaption='(In Units)' xAxisName='Date' showValues='1' labelStep='2' >";
if (!$strXML) {
echo "<br> !-- strXML not established --!";
exit(); } else { echo "<br> !-- strXML established --!"; }

// Connet to the DB
$link = connectToDB();
if (!$link) {
echo "<br> !-- Data Base connection not established --!";
exit(); } else { echo "<br> !-- Data Base connection established --!"; }

// Now, we get the data for that factory
$strQuery = "SELECT id_fecha AS Fecha, $qTxn AS Txns FROM `datos` WHERE id_prod = '$qProd' AND id_ambt = '$qAmbt' AND '$qTxn' = '$qTxn' AND id_fecha BETWEEN $qFecha AND $qFecha2";

if (!$strQuery) {
echo "<br> !-- strQuery not established --!";
exit(); } else { echo "<br> !-- strQuery established --!";
echo $strQuery; }

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

if (!$result) {
echo "<br> !-- result without RESULT --!";
exit(); } else { echo "<br> !-- result with RESULTS --!";
echo $result; }



// Iterate through each factory
if ($result) {
while($ors = mysql_fetch_array($result)) {
// Here, we convert date into a more readable form for set label.
$strXML .= "<set label='" . datePart("d",$ors['Fecha']) . "/" . datePart("m",$ors['Fecha']) . "' value='" . $ors['Txns'] . "'/>";
}
}
mysql_close($link);

// Close <chart> element
$strXML .= "</chart>";

// Create the chart - Column 2D Chart with data from strXML
echo renderChart("includes/Column2D.swf", "", $strXML, "TBP's", 600, 300, false, false);
?>

</center>
</body>
</html>



If you need more details about the site's structure just question me and i'll be glad to shared it.



#6 Guest_Angshu_*

Guest_Angshu_*
  • Guests

Posted 29 August 2011 - 07:36 AM

Hi,

Thanks for your response.

Could you please send us the generated XML code to look into the issue?

Awaiting for your response.

#7 Jesús

Jesús

    Advanced Member

  • Members
  • PipPipPipPip
  • 50 posts

Posted 29 August 2011 - 04:41 PM

Hi Angshu !!

I think that it is the problem, i dont have a XML code generated.

So my question. Is it completely necessary generate a XML code?? I mean, there's no way to plot the data without a XML code??

Because i would like to use the data from the query on fuionchart functions directly.

Thanks for your help.

#8 Jesús

Jesús

    Advanced Member

  • Members
  • PipPipPipPip
  • 50 posts

Posted 29 August 2011 - 05:23 PM

Angshu,

I've tried to understand the code source, and it seems like i created the xml code with the dataxml method. So, reading my code i can say that i generating the xml code with the function $strXML, now, how can i see the generated code??

#9 Jesús

Jesús

    Advanced Member

  • Members
  • PipPipPipPip
  • 50 posts

Posted 30 August 2011 - 12:25 AM

Angshu,


I kept working on my source code, and doing a debug i found this:


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR...ansitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>GRAFINCANDO</title> <script LANGUAGE="Javascript" SRC="includes/charts/FusionCharts.js"></SCRIPT> </head><br style="box-sizing: border-box; "><body> <center><br style="box-sizing: border-box; "><!-- START Code Block for Chart TBPS --><div id="TBPSDiv"> Chart </div><script type="text/javascript" ><!-- // Instantiate the Chart var chart_TBPS = new FusionCharts( { "swfUrl" : "includes/charts/Column2D.swf", "width" : "800", "height" : "500", "renderAt" : "TBPSDiv", "dataFormat" : "xml", "id" : "TBPS", "wMode" : "opaque", "dataSource" : "<chart caption='Producto' subcaption='(TXNS)' xAxisName='Fecha' showValues='1' labelStep='2' ><set label='20110702' value='1187071' /><set label='20110703' value='760006' /><set label='20110704' value='971380' /><set label='20110705' value='878392' /></chart>" } ).render();// --></script><!-- END Script Block for Chart TBPS --><br style="box-sizing: border-box; "> </center></body></html>
AND THIS IS THE ERROR


#10 Guest_Angshu_*

Guest_Angshu_*
  • Guests

Posted 30 August 2011 - 06:56 AM

Hi,

Thanks for your response.

FusionCharts uses XML or JSON data to render the charts. In both data format, the data file (or string) consists of data to be rendered, chart settings and cosmetics.

You can see the XML code form your browser's view-source .

Hope this helps.

#11 Jesús

Jesús

    Advanced Member

  • Members
  • PipPipPipPip
  • 50 posts

Posted 30 August 2011 - 03:26 PM

Angshu,


I kept working on my source code, and doing a debug i found this:


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR...ansitional.dtd"><htmlxmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>GRAFINCANDO</title> <script LANGUAGE="Javascript" SRC="includes/charts/FusionCharts.js"></SCRIPT> </head><br style="box-sizing: border-box; "><body> <center><br style="box-sizing: border-box; "><!-- START Code Block for Chart TBPS --><div id="TBPSDiv">Chart </div><script type="text/javascript" ><!-- // Instantiate the Chart var chart_TBPS = new FusionCharts( { "swfUrl" :"includes/charts/Column2D.swf", "width" : "800", "height" : "500", "renderAt" : "TBPSDiv", "dataFormat" : "xml", "id" : "TBPS", "wMode" :"opaque", "dataSource" : "<chart caption='Producto' subcaption='(TXNS)' xAxisName='Fecha' showValues='1' labelStep='2' ><set label='20110702' value='1187071' /><set label='20110703' value='760006' /><set label='20110704' value='971380' /><set label='20110705' value='878392' /></chart>" } ).render();// --></script><!-- END Script Block for Chart TBPS --><br style="box-sizing: border-box; "> </center></body></html>
AND THIS IS THE ERROR


#12 Jesús

Jesús

    Advanced Member

  • Members
  • PipPipPipPip
  • 50 posts

Posted 01 September 2011 - 03:30 PM

Hi Angshu,

Do you have some idea about what could be the error ??

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR...ansitional.dtd"><htmlxmlns=" http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>GRAFINCANDO</title> <script LANGUAGE="Javascript" SRC="includes/charts/FusionCharts.js"></SCRIPT></head><br style="box-sizing: border-box; "><body> <center><br style="box-sizing: border-box; "><!-- START Code Block for Chart TBPS --><div id="TBPSDiv">Chart </div><script type="text/javascript" ><!-- // Instantiate the Chart var chart_TBPS = new FusionCharts( { "swfUrl":"includes/charts/Column2D.swf", "width" : "800", "height" : "500", "renderAt" : "TBPSDiv", "dataFormat" : "xml", "id" : "TBPS", "wMode":"opaque", "dataSource" : "<chart caption='Producto' subcaption='(TXNS)' xAxisName='Fecha' showValues='1' labelStep='2' ><set label='20110702' value='1187071' /><set label='20110703' value='760006' /><set label='20110704' value='971380' /><set label='20110705' value='878392' /></chart>" } ).render();// --></script><!-- END Script Block for Chart TBPS --><br style="box-sizing: border-box; "> </center></body></html>
AND THIS IS THE ERROR