List of Functions | ||||||||||||||||||
Here is a list of the functions defined in FusionCharts PHP Class (FusionCharts_Gen.php). 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, chart width, and chart height. One can also specify an ID to the chart for JavaScript Interaction. If you use the isTransparent parameter, the chart will be ready for transparent mode. To set the chart to transparent, you need to set the bgApha chart parameter using the setChartParam() or setChartParams() function. Parameters: | ||||||||||||||||||
| ||||||||||||||||||
Example: $FC= new FusionCharts("Column3D, "350", "250"); | ||||||||||||||||||
Back to top ![]() | ||||||||||||||||||
Public Functions | ||||||||||||||||||
Configuration Functions | ||||||||||||||||||
setRenderer(string $renderer) | ||||||||||||||||||
Sets the Rendering mode of the chart. A chart can render in either Flash or JavaScript mode. Parameters: |
||||||||||||||||||
|
||||||||||||||||||
Example: $FC= new FusionCharts("Column3D, "350", "250"); $FC->setRenderer('javascript'); |
||||||||||||||||||
enablePrintManager(Boolean $directWriteToPage) | ||||||||||||||||||
Enables Print Manager for Mozilla browsers. This function adds a small JavaScript snippet to the page which enables the Managed Print option for Mozilla based browsers. Parameters: |
||||||||||||||||||
|
||||||||||||||||||
Returns a blank string when the code is directly written to page, otherwise, the JavaScript enabling the Print Manager is returned as string. Example: $FC= new FusionCharts("Column3D, "350", "250"); $FC->enablePrintManager(); NOTE : The JavaScript which is generated from this code is as follows: <script type=\"text/javascript\"><!-- if(FusionCharts && FusionCharts.printManager) FusionCharts.printManager.enabled(true); // --> </script> |
||||||||||||||||||
setWindowMode(string $mode) | ||||||||||||||||||
Explicitly sets window mode of a chart when rendered in flash mode. The possible window modes are - window, transparent and opaque. This setting will work only when chart is rendered in using flash renderer. Parameters: |
||||||||||||||||||
|
||||||||||||||||||
Example: $FC= new FusionCharts("Column3D, "350", "250"); $FC->setWindowMode('transparent'); NOTE: Transparent mode can also be set using the constructor. This mode prepares the chart for transparent background. To set the chart transparent, you need to set the bgApha chart parameter using the setChartParam() or setChartParams() function. |
||||||||||||||||||
setParamDelimiter(string $strDelm) | ||||||||||||||||||
Sets the delimiter for lists of chart attributes that are passed to functions like setChartParams, addDataset, addChartData, etc. Delimiter is the character used to separate consecutive attributes for various chart elements. The default delimiter is semicolon (;). Parameter: | ||||||||||||||||||
| ||||||||||||||||||
Note: You can use this function any number of times in a single code block for a chart. By defining a new delimiter you can use the earlier delimiter as a regular character in chart attributes. Example : $FC->setParamDelimiter("|"); $FC->setChartParams("caption=Monthly Report|subCaption=June;July;September|bgColor=efefdd"); $FC->setParamDelimiter("\n"); $FC->addDataset("June", "color=009900\nshowValues=0); | ||||||||||||||||||
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/"); | ||||||||||||||||||
setChartMessage(string $msgParam) |
||||||||||||||||||
Sets various chart messages. For more on chart messages please see the Changing chart messages page. Parameter: |
||||||||||||||||||
|
||||||||||||||||||
Example : $FC->setChartMessage("ChartNoDataText=Chart Data not provided;PBarLoadingText=Please Wait.The chart is loading..."); |
||||||||||||||||||
setInitParam( string $tname, string $tvalue) |
||||||||||||||||||
Sets the chart’s initializing parameters and adds extra chart settings as well. Parameters: |
||||||||||||||||||
|
||||||||||||||||||
Example: $FC->setInitParam("debugmode",true); $FC->setInitParam("registerWithJS",false); $FC->setInitParam("bgColor","FF00FF"); $FC->setInitParam("scalemode","noscale"); $FC->setInitParam("lang","ENG"); |
||||||||||||||||||
setOffChartCaching(Boolean $SWFNoCache) |
||||||||||||||||||
Determines whether the chart SWF files are to be cached or not. If this function is not used, the browser will cache the charts. One can stop caching by setting the parameter to true. Parameter: |
||||||||||||||||||
|
||||||||||||||||||
Example: $FC->setOffChartCaching(true); |
||||||||||||||||||
Back to top ![]() | ||||||||||||||||||
Generic Data Handling Functions | ||||||||||||||||||
setChartParam(string $paramName, string $paramValue) | ||||||||||||||||||
Sets a single attribute at a time for the chart. Attributes listed in the <chart> element section in Chart XML Reference can be used here. Parameters: | ||||||||||||||||||
| ||||||||||||||||||
Example: $FC->setChartParam("caption","Monthly Sales"); | ||||||||||||||||||
setChartParams(string $strParams) | ||||||||||||||||||
Sets multiple attributes for the chart through one function. Multiple attributes from <chart> 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 the attributes belong to the category set of a multi-series chart. 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"); | ||||||||||||||||||
addCategory(string $label[, string $catParams, string $vlineParams]) | ||||||||||||||||||
Adds a single category label information at a time. This function is used only when creating non single series charts like multi-series, Stacked, Combination, multi-series Stacked, Scatter and Bubble charts. Parameters: | ||||||||||||||||||
| ||||||||||||||||||
Example: $FC->addCategory("Week 1"); Add Vline: $FC->addCategory("","","color=FF0000") |
||||||||||||||||||
addDataset(string $seriesName[, string $datasetParams]) | ||||||||||||||||||
Adds a dataset to multi-series, Stacked, Combination, multi-series Stacked, Scatter and Bubble charts. 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, string $vlineParams]) | ||||||||||||||||||
Provides chart data. For single series charts $params must be passed having at least an attribute "label=foo". The parameter 'label' specifies the category label name for the data. For multi-series, stacked, combination and multi-series stacked charts $params is optional. In these charts category label is defined using addCategory() function. Parameters: | ||||||||||||||||||
| ||||||||||||||||||
Special Usage Cases:
|
||||||||||||||||||
Example: For Single-Series Charts : $FC->addChartData("40800","label="Week 1"); $FC->addChartData("31400","label="Week 2;color=ff0000;link=http://www.FusionCharts.com"); For Multi-Series Charts: $FC->addChartData("40800"); $FC->addChartData("31400","link=http://www.FusionCharts.com"); Add Vline : Call FC.addChartData("","","color=FF0000") |
||||||||||||||||||
Back to top ![]() | ||||||||||||||||||
Chart Specific Functions | ||||||||||||||||||
createMSStDataset() | ||||||||||||||||||
Creates the primary dataset for multi-series stacked chart. Note that this function is applicable only for multi-series Stacked Column 2D Chart and Multi-Series Stacked Column 2D Dual Y Chart. Example: FC->createMSStDataset(); | ||||||||||||||||||
addMSStSubDataset(string $seriesName, string $datasetParams) | ||||||||||||||||||
Adds sub-dataset to multi-series stacked chart's primary dataset created using the createMSStDataset() function. This function is applicable only for multi-series Stacked Column 2D Chart and multi-series Stacked Column 2D Dual Y Chart. Parameters: | ||||||||||||||||||
| ||||||||||||||||||
Note: Remember to use this function immediately after the createMSStDataset() function and add data values pertaining to the dataset immediately after using this function. Example: //Add primary dataset $FC->createMSStDataset(); //Add sub-dataset within a primary dataset $FC->addMSStSubDataset("Product A", ""); //Add data for 'Product A' $FC->addChartData("30"); $FC->addChartData("26"); | ||||||||||||||||||
addMSLineset(string $seriesName, string $linesetParams) | ||||||||||||||||||
Adds lineset to multi-series stacked chart. This line goes as per the secondary y-axis Scale. Note that this function is applicable only for multi-series Stacked Column 2D Dual Y Chart. Parameters: | ||||||||||||||||||
| ||||||||||||||||||
Note: The data for the lineset declared using this function is added using the addMSLinesetData() function. Example: //Add a lineset $FC->addMSLineset("Cost as %25 of Revenue","lineThickness=4"); //Add data for lineset $FC->addMSLinesetData("57"); $FC->addMSLinesetData("68"); | ||||||||||||||||||
addMSLinesetData(string $value[, string $params, string $vlineParams]) | ||||||||||||||||||
Adds a line to multi-series stacked chart's lineset. This function is applicable only for Multi-Series Stacked Column 2D Dual Y Chart. Parameters: | ||||||||||||||||||
| ||||||||||||||||||
Note: Remember to use this function immediately after addMSLineset() function. Example: //Add lineset $FC->addMSLineset("Cost as %25 of Revenue","lineThickness=4"); //Add data for lineset $FC->addMSLinesetData("57"); $FC->addMSLinesetData("68"); |
||||||||||||||||||
setGridParams(string $gridParams) |
||||||||||||||||||
Sets the chart’s parameters. Note that you cannot use the setChartParam() or setChartParams()function to set Grid chart’s parameters. This function is applicable only for Grid chart. Parameter: |
||||||||||||||||||
|
||||||||||||||||||
Back to top ![]() | ||||||||||||||||||
Trendlines and Vtrendlines Functions | ||||||||||||||||||
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"); |
||||||||||||||||||
addVTrendLine(string $vtlineParams) | ||||||||||||||||||
Adds a vertical trendline to Bubble Chart or Scattered Chart. All attributes for the <line> element of <vtrendlines> element, for example, startValue, endValue, color, displayValue, isTrendZone, showOnTop etc., can be passed here. Parameter: | ||||||||||||||||||
| ||||||||||||||||||
Example: $FC->addVTrendLine("startValue=35;endValue=36"); $FC->addVTrendLine("startValue=0;endValue=20;alpha=5;color=00FF00"); |
||||||||||||||||||
Back to top ![]() | ||||||||||||||||||
Colors & Styles Functions | ||||||||||||||||||
defineStyle(string $styleName, string $styleType, string $styleParams) | ||||||||||||||||||
Defines a chart's style. A style needs to be defined first and then apply to chart a object using applyStyle() function. Parameters: | ||||||||||||||||||
| ||||||||||||||||||
Example: $FC->defineStyle("MyFirstFontStyle", "font", "font=Verdana; size=12; color=FF0000; bgColor=FFFFDD;borderColor=666666"); $FC->defineStyle("MyFirstGlow","Glow","color=FF5904;alpha=75"); | ||||||||||||||||||
applyStyle(string $toObject, string $styles) | ||||||||||||||||||
Applies a style, defined by the defineStyle() function, to chart objects. Parameters: | ||||||||||||||||||
| ||||||||||||||||||
Example: //Define First Style element named MyFirstFontStyle $FC->defineStyle("MyFirstFontStyle","font","font=Verdana;size=12;color=FF0000; bgColor=FFFFDD;borderColor=666666"); //Define Second Style element named - MyFirstGlow $FC->defineStyle("MyFirstGlow","Glow","color=FF5904;alpha=75"); // Apply Style $FC->applyStyle("CAPTION","MyFirstFontStyle"); // Apply Style $FC->applyStyle("YAXISNAME","MyFirstGlow"); //One can add multiple style in one item using applyStyle function by this way: $FC->applyStyleFC("XAXISNAME", "MyFirstGlow, MyFirstFontStyle"); Example: $FC->setGridParams("showPercentValues=1;showShadow=1"); $FC->setGridParams("numberItemsPerPage=6"); | ||||||||||||||||||
addColors(string $colorList) | ||||||||||||||||||
Adds and apply user-defined colors to chart dataplots. Although FusionCharts XT has a set of colors by default, this function allows the developers to provide own set of colors. Parameter: | ||||||||||||||||||
| ||||||||||||||||||
Example: $FC->addColors("FF0000;00FF00;0000FF;FFFF00;00FFFF"); | ||||||||||||||||||
clearUserColor() | ||||||||||||||||||
Clears the color(s) that has been added using addColors function. Example: $FC->clearUserColor(); | ||||||||||||||||||
Back to top ![]() | ||||||||||||||||||
Array Handling Functions | ||||||||||||||||||
addCategoryFromArray(string $categoryArray) | ||||||||||||||||||
Adds chart category labels from array. Parameter: | ||||||||||||||||||
| ||||||||||||||||||
Example: // Category Array List $categoryArray[0]="Week 1"; $categoryArray[1]="Week 2"; $categoryArray[2]="Week 3"; $categoryArray[3]="Week 4"; // Add category names $FC->addCategoryFromArray ($categoryArray); | ||||||||||||||||||
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 two dimensional array (n rows x 2 columns):
For multi-series/Stacked/Combination charts:
$dataCatArray (required only for multi-series/Stacked/Combination charts)
| ||||||||||||||||||
Example: Single Series Chart: //Add Category labels $arrData[0][0]="Week 1"; $arrData[1][0]="Week 2"; $arrData[2][0]="Week 3"; $arrData[3][0]="Week 4"; //Add chart Data $arrData[0][1]="100"; $arrData[1][1]="200"; $arrData[2][1]="300"; $arrData[3][1]="400"; $FC->addChartDataFromArray($arrData); Multi-Series/Stacked/Combination Charts: //Store Name of Products as category labels $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"; //Series Name $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"; //Series Name $arrData[1][1] = "color=0000ff"; // Dataset Parameters $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 Using with PHP Class section. | ||||||||||||||||||
Back to top ![]() | ||||||||||||||||||
Database Handling Functions | ||||||||||||||||||
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");
or
$FC->setDataBaseType("mysql"); | ||||||||||||||||||
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"; $result = mysql_query($strQuery); $FC->addCategoryFromDatabase($result, "weekNames"); For detailed examples on FusionCharts PHP Class' Database Handling functions please go through the Using with PHP Class section. | ||||||||||||||||||
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: $strQuery = "select weekNames,revenue from Sales order by weekNames"; $result = mysql_query($strQuery); $FC->addDatasetsFromDatabase($result, "weekNames", "revenue"); 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"; $result = mysql_query($strQuery); $FC->addDataFromDatabase($result, "revenue", weekNames"); For detailed examples on FusionCharts PHP Class' Database Handling functions please go through the section Using with PHP Class | ||||||||||||||||||
Back to top ![]() | ||||||||||||||||||
XML Generating & Chart Rendering 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 Data URL method. Return Type: | ||||||||||||||||||
| ||||||||||||||||||
Example: $xml=$FC->getXML(); | ||||||||||||||||||
mixed 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: | ||||||||||||||||||
Return Type: mixed
Example: $chartHTML = $FC->renderChart(true, false); | ||||||||||||||||||
renderChartFromExtXML(string $dataXML, [Boolean $renderAsHTML]) | ||||||||||||||||||
This function is deprecated. Please use renderChartFromExtData() instead. 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="<chart><set value='100' name='Product A'/><set value='120' name='Product B'/></chart>"; $FC = new FusionCharts("Column3D","300","250"); $FC->renderChartFromExtXML($xml); | ||||||||||||||||||
renderChartFromExtData(string $data, [string $dataformat][, Boolean $renderAsHTML]) |
||||||||||||||||||
Renders chart from data which has not been created through the class. After creating chart object and setting relative chart file path, this function can be called to set complete XML or JSON to the chart. The XML or JSON data needs to be passed as string. You can convert an array to proper JSON string using PHP's json_encode function. To know more on XML, please read the FusionCharts XT Data Formats > XML section. To know more on JSON, please read the FusionCharts XT Data Formats > JSON section. Parameter: |
||||||||||||||||||
|
||||||||||||||||||
Example: $data = array( "chart"=> array( "caption" => "Weekly Sales Summary" , "xAxisName" => "Week", "yAxisName" => "Sales", "numberPrefix" => "$" ), "data" => array( array( "label" => "Week 1", "value" => "14400" ), array( "label" => "Week 2", "value" => "19600" ), array( "label" => "Week 3", "value" => "24000" ), array( "label" => "Week 4", "value" => "15700" ) ) ); $json= json_encode($data);; $FC = new FusionCharts("Column3D","300","250"); $FC->renderChartFromExtData($json, 'json' ); |
||||||||||||||||||