Sign in to follow this  
jgcrossman2

Mysql, Php To Xy Chart

Recommended Posts

I would like to create an XY Scatter chart from data in a MySQL database.

 

I have done this successfully with a 2D line chart where the key elements are:

 

$FC->addCategoryFromDatabase($result, "Date");

$ctrlField = "Date";

$valueField = "IRP_System;SPY";

$FC->addDatasetsFromDatabase($result, $ctrlField, $valueField,$datasetParamArray,"");

 

 

I note that the format for XY Charts is:

 

$FC->addDataSet("Server 1","anchorRadius=6");

$FC->addChartData("21","y=2.4");

 

 

 

How does that translate when one wants to pull the data off of a MySQL database?

 

I tried this but it did not work...

 

$strQuery = "SELECT `Ticker`, `PB`, `ROE` FROM `PEcalc`";

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

 

if ($result) {

$FC->addCategoryFromDatabase($result, "Ticker");

$ctrlField = "Ticker";

$valueField = "ROE;PB";

$FC->addDatasetsFromDatabase($result, $ctrlField, $valueField);

}

 

I suspect that

addCategoryFromDatabase

and

addDatasetsFromDatabase

 

are not properly configured or named.

 

Any help, including links to an existing article or document that I failed to find would be much appreciated.

 

BTW, trying to shoehorn in a $row[x] calls using a mysql_query into a while ... mysql_fetch_row... construction did not work. But if someone has a suggestion along those lines, I am all ears.

 

Thanks in advance,

 

John

Share this post


Link to post
Share on other sites
Guest Sashibhusan

Hi,

 

Welcome to FusionCharts Forum.

 

We are glad to hear that you have managed of your own to resolve the issue.

 

However, with regard to your query on "make the legend values into hyperlinks", currently this is not supported by FusionCharts.

 

For more information on "XML/JSON Attributes for Legend", please follow the link below:

http://docs.fusioncharts.com/charts/contents/?AttDesc/Legend.html

 

Hope this helps!

Share this post


Link to post
Share on other sites

Hi,

 

I can't view Chart created. I am just getting the message 'Connected Successfully' Please help. Here is my code:

 

<?php
include("D:/FusionCha/FusionCharts.php");
include("D:/FusionCha/DBConn.php");
?>
<html>
<title> FusionChart</title>
<head>
<script language="javascript" src="D:/FusionCha/FusionCharts.js"></script>
 
</head>
<body>
<center>
<?php
 
//connect to the DB
$link= connectToDB();
//$strXML will be used to store the entire XML document generated
//Generate the graph element
$strXML = "<graph caption='Worklog repor' subCaption='Month wise' xaxisname='Current Month' yaxisname='Blood Pressure' yAxisMaxValue='200'
animation='1'>";
 
//Fetch records from database
$query= "select Password,info_r3_c1 from work_data1";
$result = mysql_query($query) or die(mysql_error());
//echo $result;
 
$row=mysql_fetch_array($result);
 
 
//Iterate through each patient blood pressure systole
 
 
//Generate the setname and value
//echo $row['Date'];
//$date=;
//$sr=;
//echo $date;
//echo $row['Systole_reading'];
//$strXML.="<set name='' value='". $row['systole_reading']."'/>";
//$strXML.="<set name='ondate' value".$result['ondate']."'/>";
 
$strXML .="<set name='" . $row['Password'] . "' value='" . $row['info_r3_c1'] . "' />";
 
mysql_free_result($result);
 
 
 
 
//Finally, close <graph> element
$strXML .= "</graph>";
//Create the chart - Pie 3D Chart with data from $strXML
echo renderChartHTML("D:/FusionCha/FusionCharts/Column2D.swf", "", $strXML, "Password", 650, 450,false);
//echo renderChartHTML("./Charts/FCF_Bar2D.swf", "", $strXML, "ad", 800, 600, false);
 
?>
 
</center>
 
</body>
 
</html>

Share this post


Link to post
Share on other sites

I just see the message 'Connected Successfully' and 'Chart' when I run my php file, but not seeing any chart. Please help. Here is my code:

 

<?php

include("D:/FusionCha/FusionCharts.php");
include("D:/FusionCha/DBConn.php");
?>
<html>
<title> FusionChart</title>
<head>
<script language="javascript" src="D:/FusionCha/FusionCharts.js"></script>
 
</head>
<body>
<center>
<?php
 
//connect to the DB
$link= connectToDB();
//$strXML will be used to store the entire XML document generated
//Generate the graph element
$strXML = "<graph caption='Worklog repor' subCaption='Month wise' xaxisname='Current Month' yaxisname='Blood Pressure' yAxisMaxValue='200'
animation='1'>";
 
//Fetch records from database
$query= "select Password,info_r3_c1 from work_data1";
$result = mysql_query($query) or die(mysql_error());
//echo $result;
 
$row=mysql_fetch_array($result);
 
 
 
 
 
//Generate the setname and value
//echo $row['Date'];
//$date=;
//$sr=;
//echo $date;
//echo $row['Systole_reading'];
//$strXML.="<set name='' value='". $row['systole_reading']."'/>";
//$strXML.="<set name='ondate' value".$result['ondate']."'/>";
 
$strXML .="<set name='" . $row['Password'] . "' value='" . $row['info_r3_c1'] . "' />";
 
mysql_free_result($result);
 
 
 
 
//Finally, close <graph> element
$strXML .= "</graph>";
//Create the chart - Pie 3D Chart with data from $strXML
echo renderChart("D:/FusionCharts/Column2D.swf", "", $strXML, "Password", 650, 450,false,true);
//echo renderChartHTML("./Charts/FCF_Bar2D.swf", "", $strXML, "ad", 800, 600, false);
 
?>
 
</center>
 
</body>
 
</html>

Share this post


Link to post
Share on other sites
Guest Sashibhusan

Hi,

 

Could you please try once by providing the relative URLs (and not absolute URLs) of "FusionCharts.php", "DBConn.php", "FusionCharts.js" and chart SWF file, in your code?

 

Also, please confirm, whether you've copied FusionCharts.js, jquery.min.js, FusionCharts.HC.js and FusionCharts.HC.Charts.js in the same folder where FusionCharts.js is present and included the correct path of "FusionCharts.js" in your application.

 

Hope this helps!

 

Awaiting your response.

Share this post


Link to post
Share on other sites
Guest Sashibhusan

Hi Preeti,

 

Could you please provide the scaled down sample code and the output XML string generated in $strXML by your code (by echoing $strXML, you can get the XML string), so that we can test and better investigate the exact issue?

 

Also, we recommend relative URLs instead of absolute paths of your files in your code. So, could you please provide the screen shot of what errors you are getting in this context?

 

Also, please confirm once, whether any new-line characters included in the XML string which is generated by your code. New line characters in XML/JSON string cause JavaScript error which can cause displaying "Chart" instead of rendering the chart.

 

Hope this helps!

 

Awaiting your response.

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