addDataFromDatabase syntax help needed
FusionCharts Forum
Home       Members    Calendar    Who's On
Welcome Guest ( Login | Register )
        



addDataFromDatabase syntax help needed Expand / Collapse
Author
Message
Posted 1/26/2008 6:56:13 PM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: Forum Members
Last Login: 7/19/2008 6:20:56 PM
Posts: 5, Visits: 17
I am trying to bring color info along from my DB table and I can't figure out the syntax of $FC->addDataFromDatbase. I'm using the example from "Using FusionCharts PHP Class > Plotting data from a database." I've added the color column to the $strquery and the color numbers are available (if I substitute "Color" for "ResourceName" in the code below the hex numbers come through as the names) but the documentation is unclear to me on the necessary syntax of "addDataFromDatabase" beyond the data value and name.

addDataFromDatabase(resource $query_result, string $db_field_ChartData[, string $db_field_CategoryNames, string $strParam, string $link])

Adds chart data and category names from database. This function is specially designed for single-series charts, but can be used to provide chart values for a single dataset in multi-series/stacked/combination charts.

Parameters:

* $query_result = SQL query result to fetch dataset from database.
* $db_field_ChartData = database field that contains data values.
* $db_field_CategoryNames = database field that contains category names.(Optional for multi-serise/stacked/combination charts)
* $strParam = (Optional) delimiter separated attribute list for dataplots.
* $link = (Optional) Adds hyperlink feature to dataplots. This adds the link attribute to dataplots or elements.It can be a simple URL say, "http://www.google.com" or another page say, "Drill/Detailed.php" etc. For details on drill down and creating links using FusionCharts, please go through the section Drill Down Charts.

This parameter has a link place holder format that helps creating dynamic links. Anything placed between ## and ##
(for example, . FactoryID in "Detailed.php?FId=##FactoryID##") will be regarded as a field/column name in the SQL query result. Value from that column will dynamically replcae that place holder. Hence, for each dataplot in the chart the link values will be different.

For detailed exmaple on this feature, please refer to Creating Drilldown charts in "Using With PHP Class" section.



Example:

$strQuery = "select weekNames,revenue from Sales order by weekNames where CMonth=1";
$result = mysql_query($strQuery);
$FC->addDataFromDatabase($result, "revenue", weekNames");


//Store chart data values in 'total' column/field and category names in 'ResourceName'
$strQuery = "SELECT a.ResourceID, b.ResourceName, sum(a.Quantity) as total, b.Color FROM fus_freewill_giving a, fus_resource_master b WHERE a.ResourceId=b.ResourceId GROUP BY a.ResourceId,b.ResourceName";
$result = mysql_query($strQuery) or die(mysql_error());

//Pass the SQL Query result to the FusionCharts PHP Class function
//along with field/column names that are storing chart values and corresponding category names
//to set chart data from database
if ($result) {
$FC->addDataFromDatabase($result, "total", "ResourceName");
}


Any suggestions are much appriciated.
Post #4137
Posted 1/28/2008 5:46:52 AM
Supreme Being

Supreme BeingSupreme BeingSupreme BeingSupreme BeingSupreme BeingSupreme BeingSupreme BeingSupreme Being

Group: Moderators
Last Login: Today @ 5:38:52 AM
Posts: 884, Visits: 1,420
hi,

I am afraid as of now you can not add colors from database and apply them to the chart dataplots.

In your case it may be so that you are supplying the color values as $db_field_CategoryNames, hence they are showing as names.

Regards,

Sudipto Choudhury
FusionCharts Team

Post #4167
Posted 1/28/2008 9:02:56 PM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: Forum Members
Last Login: 7/19/2008 6:20:56 PM
Posts: 5, Visits: 17
So then I guess I'm confused by the documentation section that I copied above. It seems that " $strParam = (Optional) delimiter separated attribute list for dataplots" can be used in the syntax to choose attributes...maybe those are only the chart attributes seeing as $strParam is used earlier in the code to define the chart attributes and is passed using
FC->setChartParams($strParam);


At first I just wasn't sure what the brackets in the documentation indicated other than optional strings. Then I studied the drilldown variation of addDataFromDatabase:

if ($result)
{
$FC->addDataFromDatabase($result, "total", "FactoryName","","Detailed.php?FactoryId=##FactoryID##");
}

and concluded that I might just needed some empty quotes to let ..._Gen.php know where my attributes were located. Now it seems that I can't pass dataset attributes afterall.
Post #4177
Posted 1/28/2008 9:51:10 PM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: Forum Members
Last Login: 7/19/2008 6:20:56 PM
Posts: 5, Visits: 17
OK, I should have thought of this earlier...by placing a concatenate in the sql select statement with the proper delimiter I can build everything into the $db_field_CategoryNames field that I desire and get my result. So, instead of this:
//Store chart data values in 'total' column/field and category names in 'ResourceName'
$strQuery = "SELECT a.ResourceID, b.ResourceName, sum(a.Quantity) AS total FROM fus_freewill_giving a, fus_resource_master b WHERE a.ResourceId=b.ResourceId GROUP BY a.ResourceId,b.ResourceName";
$result = mysql_query($strQuery) or die(mysql_error());
//Pass the SQL Query result to the FusionCharts PHP Class function
//along with field/column names that are storing chart values and corresponding category names
//to set chart data from database
if ($result) {
$FC->addDataFromDatabase($result, "total", "ResourceName");
}

I have this:
//Store chart data values in 'total' column/field and category names and attributes in 'Resource'
$strQuery = "SELECT a.ResourceID, CONCAT(b.ResourceName, ';color=', b.Color, ';isSliced=', b.Sliced) AS Resource, sum(a.Quantity) AS total FROM fus_freewill_giving a, fus_resource_master b WHERE a.ResourceId=b.ResourceId GROUP BY a.ResourceId,b.ResourceName";
$result = mysql_query($strQuery) or die(mysql_error());
//Pass the SQL Query result to the FusionCharts PHP Class function
//along with field/column names that are storing chart values and corresponding category names
//to set chart data from database
if ($result) {
$FC->addDataFromDatabase($result, "total", "Resource");
}

I added a "Sliced" column to my DB table and it functions as expected along with the Color. I'm very new to FusionCharts Free so if this method seems inappropriate in any way please let me know. I'm using the "simple method" right now and haven't tried it with the "Using FusionCharts PHP Class > Plotting data from a database dataURL" method but I think the principle should still hold and the string should be passed accordingly. When I get to the point of trying it I will report any problems here.
Post #4178
Posted 1/29/2008 12:17:10 AM
Supreme Being

Supreme BeingSupreme BeingSupreme BeingSupreme BeingSupreme BeingSupreme BeingSupreme BeingSupreme Being

Group: Moderators
Last Login: Today @ 5:38:52 AM
Posts: 884, Visits: 1,420
hi,

Thanks for your extensive work on this feature. You have worked it right and i hope your code is working fine too. Just keep in mind not to set Delimiter to special characters like ' < > \

; will work fine.

Regards,

Sudipto Choudhury
FusionCharts Team

Post #4200
« Prev Topic | Next Topic »


Permissions Expand / Collapse

All times are GMT -7:00, Time now is 6:03pm


Execution: 0.031.