FusionCharts PHP Class API > List of Functions |
||||||||||||
Here is a list of the functions in FusionCharts PHP Class. These functions create the required XML output based on the parameters passed through and make the chart rendering process easier for you. |
||||||||||||
Constructor | ||||||||||||
FusionCharts(string $chartType, string $width, string $height[,string $chartID,boolean $isTransparent ]) |
||||||||||||
Instantiates chart object. Use the constructor to specify chart type and chart width & chart height. |
||||||||||||
Parameters: |
||||||||||||
|
||||||||||||
Example: $FC= new FusionCharts("Column3D, "350", "250"); |
||||||||||||
General Functions | ||||||||||||
setParamDelimiter(string $strDelm) |
||||||||||||
Sets the delimiter for lists of chart attributes which are passed to function like setChartParams, addDataset, addChartData etc. Delimiter is the character used to separate consecutive attributes for various chart elements. Default delimiter is semicolon (;). | ||||||||||||
Parameter: |
||||||||||||
|
||||||||||||
Note: You can use this functions any number of times in a single code block for a chart. By defining a new delimiter one can use the earlier delimiter as a regular character in chart attributes. | ||||||||||||
Example : $FC->setParamDelimiter("|"); |
||||||||||||
setSWFPath(string $SWFPath) |
||||||||||||
Sets the path of the chart SWF file. Users may need to specify the relative file path of the SWF files while using them in different applications. This function allows users to set the path. The default path for SWF file is set to the application folder itself. | ||||||||||||
Parameter: |
||||||||||||
|
||||||||||||
Example : $FC->setSWFPath("FusionCharts/"); |
||||||||||||
setChartParam(string $paramName, string $paramValue) |
||||||||||||
Sets a single chart attribute at a time. Attributes listed under <graph> element section in Chart XML Reference can be used here. | ||||||||||||
Parameters: |
||||||||||||
|
||||||||||||
Example: $FC->setChartParam("caption","Monthly Sales"); |
||||||||||||
setChartParams(string $strParams) |
||||||||||||
Sets multiple chart attributes in one function call. Multiple attributes from <graph> element section of Chart XML Reference can be passed through this function. | ||||||||||||
Parameter: |
||||||||||||
|
||||||||||||
Example: $FC->setChartParams("caption=Factory Sales;subCaption=Year 2007;bgColor=ffccff"); |
||||||||||||
setCategoriesParams(string $catParams) |
||||||||||||
Sets category set's attributes in Multi-Series charts. Attributes mentioned under the <categories> element in Chart XML Reference section can be set through this function. | ||||||||||||
Parameter: |
||||||||||||
|
||||||||||||
Example: $FC->setCategoriesParams("font=Arial;fontColor=ff0000"); |
||||||||||||
setInitParam( string $tname, string $tvalue) |
||||||||||||
Sets the chart’s initializing parameters and adds extra chart settings as well. | ||||||||||||
Parameters: |
||||||||||||
|
||||||||||||
addCategory(string $label[, string $catParams]) |
||||||||||||
Adds a single category information at a time. | ||||||||||||
Parameters: |
||||||||||||
|
||||||||||||
Example: $FC->addCategory("Week 1"); |
||||||||||||
addDataset(string $seriesName[, string $datasetParams]) |
||||||||||||
Adds a dataset to multi-series chart. |
||||||||||||
Parameters: |
||||||||||||
|
||||||||||||
Note: Remember to add data values pertaining to the dataset immediately after using this function. | ||||||||||||
Example: $FC->addDataset("This Month"); $FC->addChartData("40800"); $FC->addChartData("31400"); $FC->addDataset("Previous Month"); $FC->addChartData("38300"); Data values '40800' and '31400' will be assigned to the dataset "This Month" and the data value '38300' will be assigned to the dataset "Previous Month". |
||||||||||||
addChartData(string $value[, string $params]) |
||||||||||||
Provides chart data. For single series charts $params must be passed having atleast an attrubite "name=foo". For multiseries, stacked and combination charts $params is optional. | ||||||||||||
Parameters: |
||||||||||||
|
||||||||||||
Example: For Single-Series Charts : $FC->addChartData("40800","name="Week 1"); For Multi-Series Charts: $FC->addChartData("40800"); |
||||||||||||
addTrendLine(string $tlineParams) |
||||||||||||
Adds a trendline in the chart. All attributes for the <line> element of <trendlines> element like startValue, endValue, color, displayValue, isTrendZone, showOnTop etc. are passed here. | ||||||||||||
Parameter: |
||||||||||||
|
||||||||||||
Example : $FC->addTrendLine("startValue=89.5;endValue=98;color=FF0000;displayvalue=Roll. Avg.; thickness=2;alpha=100;isTrendZone=0;showOnTop=1"); |
||||||||||||
addColors(string $colorList) |
||||||||||||
Adds and apply user-defined colors to chart dataplots. Although FusionCharts v3 has a set of colors by default, this function allows the developers to provide own set of colors. | ||||||||||||
Parameter: |
||||||||||||
|
||||||||||||
Example: | ||||||||||||
// the hex-colour code series passed is a de-limiter separated string $FC->addColors("FF0000;00FF00;0000FF;FFFF00;00FFFF"); // ';' is the default de-limiter //the default de-limiter can be changed by the following method $FC->setParamDelimiter("|"); $FC->addColors("FF0000|00FF00|0000FF|FFFF00|00FFFF"); |
||||||||||||
setChartMessage(string $msgParam) |
||||||||||||
Sets various chart messages. For more on chart messages please see the page: Changing chart messages | ||||||||||||
Parameter: |
||||||||||||
|
||||||||||||
Example : $FC->setChartMessage("ChartNoDataText=Chart Data not provided;PBarLoadingText=Please Wait.The chart is loading..."); |
||||||||||||
Array Handling | ||||||||||||
addChartDataFromArray(array $dataArray[, array $dataCatArray]) |
||||||||||||
Adds chart data from array(s). We can use this function for both Single Series and Multi Series charts; however, the structure of the $dataArray should be different for single and multi-series charts. Also, the second parameter $dataCatArray is required only for Multi Series or Combination Charts. | ||||||||||||
Parameters: |
||||||||||||
$dataArray (required for both Single Series and Multi Series/Stacked/Combination charts) For Single Series charts a 2 dimnestional array (n rows x 2 columns):
For MultiSeries/Stacked/Combination charts:
$dataCatArray (required only for Multi Series/Stacked/Combination charts)
|
||||||||||||
Example: Single Series Chart: $arrData[0][0]="Week 1"; |
||||||||||||
Multi-Series/Stacked/Combination Charts: //Store Name of Products $arrCatNames[0] = "Week 1"; $arrCatNames[1] = "Week 2"; $arrCatNames[2] = "Week 3"; $arrCatNames[3] = "Week 4"; //Store sales data for current month $arrData[0][0] = "Current Month"; $arrData[0][1] = "color=ff0000"; // Dataset Parameters $arrData[0][2] = 567500; $arrData[0][3] = 815300; $arrData[0][4] = 556800; $arrData[0][5] = 734500; //Store sales data for previous month $arrData[1][0] = "Previous Month"; $arrData[1][1] = "color=0000ff"; // Dataset Parameter $arrData[1][2] = 547300; $arrData[1][3] = 584500; $arrData[1][4] = 754000; $arrData[1][5] = 456300; $FC->addChartDataFromArray($arrData,$arrCatNames); |
||||||||||||
For detailed examples on FusionCharts PHP Class' Array Handling function please go through the section Using with PHP Class | ||||||||||||
Database Handling | ||||||||||||
setDataBaseType(string $dbType) | ||||||||||||
Sets the type of the Database. It takes either of the two values – “mysql” or ”oracle” The default value is “mysql”. | ||||||||||||
Parameter: | ||||||||||||
| ||||||||||||
Example: | ||||||||||||
$FC->setDataBaseType("oracle"); | ||||||||||||
addCategoryFromDatabase(resource $query_result, string $categoryColumn) |
||||||||||||
Creates the set of chart Category Names from database for database driven multi-series charts. | ||||||||||||
Parameters: |
||||||||||||
|
||||||||||||
Example: $strQuery = "select distinct weekNames from Sales"; |
||||||||||||
For detailed examples on FusionCharts PHP Class' Database Handling functions please go through the section Using with PHP Class | ||||||||||||
addDatasetsFromDatabase(resource $query_result, string $ctrlField, string $valueField[, array $datasetParamArray, string $link]) |
||||||||||||
Adds datasets with data values for each dataset (only for multiseries/stacked/combination charts) from database. | ||||||||||||
Parameters: |
||||||||||||
|
||||||||||||
Note: The control Break field must be sorted. | ||||||||||||
Example: |
||||||||||||
For detailed examples on FusionCharts PHP Class' Database Handling functions please go through the section Using with PHP Class | ||||||||||||
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: |
||||||||||||
|
||||||||||||
Example: $strQuery = "select weekNames,revenue from Sales order by weekNames where CMonth=1"; |
||||||||||||
For detailed examples on FusionCharts PHP Class' Database Handling functions please go through the section Using with PHP Class | ||||||||||||
Chart rendering and XML generating functions | ||||||||||||
string getXML() |
||||||||||||
This function is used to get the full XML required for chart generation. FusionCharts PHP Class functions build specific parts of chart XML. getXML() function assembles those parts and returns the full XML. Users can use this XML to render charts in dataURL method. | ||||||||||||
Return Type: |
||||||||||||
|
||||||||||||
Example: $xml=$FC->getXML(); |
||||||||||||
Chart rendering and XML generating functions | ||||||||||||
encodeXMLChars(boolean $isEnabled) |
||||||||||||
This function is used along with the dataXML(default) method. In case the user needs to build the XML separately (dataURL method), one needs to set the parameter to false. | ||||||||||||
Parameter: |
||||||||||||
|
||||||||||||
Example: $xml=$FC->encodeXMLChars(true); |
||||||||||||
renderChart(boolean $renderAsHTML, boolean $display) |
||||||||||||
This function builds the full XML required for chart generation and also renders chart based on chart type, width and height as specified. This function does not accept any parameter, nor does it return any value. | ||||||||||||
Parameter: |
||||||||||||
|
||||||||||||
Example: | ||||||||||||
// The retuned string conforms with the JavaScript embeddeding method using FusionCharts.js $FC->renderChart(); //render as HTML $FC->renderChart(true); //returns the chart code as a string $returnValue = $FC->renderChart(true, false); |
||||||||||||
renderChartFromExtXML(string $dataXML) |
||||||||||||
Renders chart from XML which has not been created in the program. After creating chart object and setting relative SWF file path, this function can be used where the full XML is passed through. | ||||||||||||
Parameter: |
||||||||||||
|
||||||||||||
Example: $xml="<graph><set value='100' name='Product A' /><set value='120' name='Product B' /></graph>"; |
||||||||||||