tag. * ] * Version: 1.0.1 (10 November 2008) [ Fix PHP Short Tag, MSColumnLine3D Fix, Function * addDatasetsFromDatabase Modifiaction for Transposed Data, * Fix Transparent setting ] * Version: 1.0 (30 July 2008) * * FusionCharts PHP Class easily handles all FusionCharts XML elements like * chart, categories, dataset, set, Trendlines, vTrendlines, vline, styles etc. * It's easy to use. It binds data into FusionCharts XML Structures. * *********************************************************************************** */ class FusionCharts{ var $chartType; # Type of Chart var $chartID; # ID of the Chart for JS interactivity(optional) var $SWFFile; # Name of the required FusionCharts SWF file var $SWFPath; # Relative path to FusionCharts SWF files var $width; # FusionCharts width var $height; # FusionCharts height # Separator/Delimiter for list of Parameters var $del; # Chart XML string var $strXML; # Chart Series Types : 1 => single series, 2=> multi-series, # 3=> scatter and bubble, 4 => MSStacked var $seriesType; # Chart Atributes var $chartParams = array(); # List of Chart Parameters var $categoriesParam; # Categories Parameter Setting var $categoryNames = array(); # Category array for storing Category set var $categoryNamesCounter; # Category array counter var $dataset = array(); # Dataset array var $datasetParam = array(); # Dataset parameter setting array var $datasetCounter; # Dataset array counter var $setCounter; # Set array counter # trendLines var $trendLines = array(); # trendLines array var $tLineCounter; # trendLines array counter # chart messages var $chartMSG; # Stores chart messages var $chartSWF = array(); # Charts SWF array # Color var $arr_FCColors = array(); # Colorset to be applied to dataplots var $userColor= array(); # Array to store user defined colors var $userColorON; # Flag : user defined color : true or false var $userColorCounter; # Number of colors used in the user-defined color list # Cache Control var $noCache; # Flag - Range : true/false : Stops caching chart SWFs var $DataBaseType; # Flag - DataBase Type values : "mysql" => default, "Oracle". var $encodeChars; # XML for dataXML or dataURL # Advanced Chart settings var $JSC = array(); var $wMode; # Addtional variables for MSStacked charts var $MSStDataset = array(); # Store Primary Dataset var $MSStDatasetParams = array(); # Parameter setting for Primary Dataset var $MSStDatasetCounter; # Number of Primary Datasets var $MSStSubDatasetCounter; # Number of Secondary Datasets var $MSStSetCounter; # Number of data values in Dataset # lineset var $lineSet = array(); # Stores Lines/Linesets in MSStacked Dual Y charts var $lineSetParam = array(); # parametets of each line in a Lineset var $lineCounter; # Number of lines in a Lineset var $lineSetCounter; # Number of Linesets var $lineIDCounter; # LineIDs # vtrendLines array var $vtrendLines = array(); # Store vtrendLines var $vtLineCounter; # Number of vtrendLines # style array var $styles = array(); # Styles array var $styleDefCounter; # Define counter var $styleAppCounter; # Apply counter var $FC_DEFAULT_CONFIG = array() ; # Default configurations # FusionCharts Constructor # while creating FusionCharts object, the Constructor will initialize the object with values passed to it as arguments i.e. # chats parameters like chartType, width, height, chartID function FusionCharts($chartType="column2d",$width="400",$height="300",$chartID="",$isTransparent=""){ #Set mode to Transparent $this->wMode=$isTransparent; # Initilaize the Array with definition of all Charts $this->setChartArrays(); # Initilaize list of colors $this->colorInit(); # Set Chart's name $this->chartType=strtolower($chartType); # Get Chart's Series Type $this->getSeriesType(); # Set Chart's Width and Height $this->width=$width; $this->height=$height; # Set ChartID, Default is {Chart Name + Counter} # for this session is required if ($chartID==""){ # Count the number of charts rendered $chartCounter=@$_SESSION['chartcount']; if($chartCounter<=0 || $chartCounter==NULL){ $chartCounter=1; } $this->chartID=$chartType . $chartCounter; $_SESSION['chartcount']=++$chartCounter; }else{ $this->chartID=$chartID; } # Set Default Parameter Delimiter to ';' $this->del=";"; # Set Default Path to Chart SWF files $this->SWFPath=""; $this->SWFFile=$this->SWFPath . $this->chartSWF[$this->chartType][0] . ".swf"; # Initialize Parameter for category set $this->categoriesParam=""; $this->categoryNamesCounter=1; # Initialize Category Array $this->createCategory($this->categoryNamesCounter); # Initialize Dataset Variables $this->datasetCounter=0; $this->setCounter= 0; if($this->seriesType>1){ $this->setCounter++; } # Initialize MSStacked Dataset Variables if($this->seriesType==4){ $this->MSStDatasetCounter=0; $this->MSStSubDatasetCounter=0; $this->MSStSetCounter=0; $this->lineCounter=0; $this->lineSetCounter=0; $this->lineIDCounter=0; } # Initialize vTrendLines Array if($this->seriesType==3){ $this->vtLineCounter=1; $this->createvTrendLines($this->vtLineCounter); } # Initialize TrendLines Array $this->tLineCounter=1; $this->createTrendLines($this->tLineCounter); # Initialize Array to store STYLES $this->styleDefCounter=1; $this->styleAppCounter=1; $this->createStyles("definition"); $this->createSubStyles("definition","style"); $this->createSubStylesParam("definition","style",$this->styleDefCounter); $this->chartMSG=""; #Variable to store XML $this->strXML=""; $this->userColorON = false; # Flag for userColor (by default it is false) $this->userColorCounter=0; $this->noCache=false; # Cache default false $this->DataBaseType="mysql"; # default database MySql // JS Constructor $this->JSC["debugmode"]=false; # debugmode default is false $this->JSC["registerwithjs"]=false; # registerwithJS default is false $this->JSC["bgcolor"]=""; # bgcolor default not set $this->JSC["scalemode"]="noScale"; # scalemode default noScale $this->JSC["lang"]="EN"; # Language default EN $this->encodeChars=false; // initialize $this->FC_INITIALIZE(); $this->FC_INITSTATIC(); } #------------------------- Public Functions ---------------------------------------------- # Special Character function encodeXMLChars($option=true){ $this->encodeChars=$option; } # Set path where chart SWF files are stored function setSWFPath($SWFPath){ $this->SWFPath=$SWFPath; $this->SWFFile=$this->SWFPath . $this->chartSWF[$this->chartType][0] . ".swf"; } # Set Parameter Delimiter, Defult Parameter Separator is ";" function setParamDelimiter($strDelm){ $this->del=$strDelm; } # The setChartParam() function adds or changes single Chart parameter, - # it takes Parameter Name and its Value function setChartParam($paramName, $paramValue){ $this->chartParams[$paramName]=$this->encodeSpecialChars($paramValue); } # The setChartParams() function adds or changes Chart parameters # it takes list of parameters separated by delimiter # e.g. "caption=xyz caption;subCaption=abcd abcd abcd;xAxisName=x axis;yAxisName=y's axis;bgColor=f2fec0;animation=1" # Default Delimiter is ";" function setChartParams($strParams){ $listArray=explode($this->del,$strParams); foreach ($listArray as $valueArray) { $paramValue=explode("=",$valueArray,2); if($this->validateParam($paramValue)==true){ $this->chartParams[$paramValue[0]]=$this->encodeSpecialChars($paramValue[1]); } } } # The setCategoriesParams() function sets parameters for Category set function setCategoriesParams($catParams){ $this->categoriesParam .= $this->ConvertParamToXMLAttribute($catParams); } # The addCategory() function adds a Chart Category (and optional vLine element) function addCategory($label="",$catParams="",$vlineParams = "" ){ $strCatXML=""; $strParam=""; $label=$this->encodeSpecialChars($label); # Check whether vlineParam is present if($vlineParams==""){ # Check whether catParam is absent if($catParams!=""){ # Convert category Parameters into XML $strParam = $this->ConvertParamToXMLAttribute($catParams); } # Add label and parameters to category $strCatXML =""; }else{ # Add vLine $strParam = $this->ConvertParamToXMLAttribute($vlineParams); # Add vLine parameters $strCatXML=""; } # Store into categoryNames array $this->categoryNames[$this->categoryNamesCounter]=$strCatXML; # Increase Counter $this->categoryNamesCounter++; } # The addDataset() function adds a new dataset element function addDataset($seriesName, $datasetParams=""){ $this->datasetCounter++; $this->createDataset($this->datasetCounter); $this->setCounter++; $this->createDataValues($this->datasetCounter,"_" . $this->setCounter); $seriesName=$this->encodeSpecialChars($seriesName); # Create seriesName and dataset parameters $tempParam=""; $tempParam ="seriesName='" . $seriesName . "' "; $tempParam .= $this->ConvertParamToXMLAttribute($datasetParams); $colorParam=""; # Add user-defined Color if ($this->userColorON == true){ $pos = strpos(strtolower($tempParam), " color"); if ($pos === false) { $colorParam=" color='" . $this->getColor($this->datasetCounter-1) . "'"; } } # Set datasetParam array $this->datasetParam[$this->datasetCounter]=$tempParam . $colorParam; } # The addChartData() function adds chart data elements function addChartData($value="",$params="",$vlineParams = "" ){ $strSetXML=""; # Choose dataset depending on seriesType and get chart's XML switch ($this->seriesType){ case 1: case 2: $strSetXML=$this->genSSMSChartDataXML($value,$params,$vlineParams); break; case 3: $strSetXML=$this->genScatterBubbleChartDataXML($value,$params,$vlineParams); break; case 4: $strSetXML=$this->genSSMSChartDataXML($value,$params,$vlineParams); break; } # Add xml to dataset array and Increase setCounter switch ($this->seriesType){ case 1: $this->dataset[$this->setCounter]=$strSetXML; $this->setCounter++; break; case 2: case 3: $this->dataset[$this->datasetCounter]["_" . $this->setCounter]=$strSetXML; $this->setCounter++; break; case 4: $this->MSStDataset[$this->MSStDatasetCounter][$this->MSStSubDatasetCounter][$this->MSStSetCounter]=$strSetXML; $this->MSStSetCounter++; break; } } # CreateMSStDataset function creates MS-Stacked Chart's Primary dataset function createMSStDataset(){ $this->MSStDatasetCounter++; $this->MSStDataset[$this->MSStDatasetCounter]= array(); $this->MSStDatasetParams[$this->MSStDatasetCounter]=array(); } # The addMSStSubDataset() function adds MS-Stacked Charts sub-dataset function addMSStSubDataset($seriesName, $datasetParams){ $this->MSStSubDatasetCounter++; $this->MSStDataset[$this->MSStDatasetCounter][$this->MSStSubDatasetCounter]= array(); $seriesName=$this->encodeSpecialChars($seriesName); $tempParam=""; # Creating seriesName $tempParam ="seriesName='" . $seriesName . "' "; $tempParam .= $this->ConvertParamToXMLAttribute($datasetParams); $this->MSStSetCounter++; # Add Parameter to MSStDatasetParams array $this->MSStDatasetParams[$this->MSStDatasetCounter][$this->MSStSubDatasetCounter]=$tempParam; } # The addMSLineset() function adds Lineset element to MS-Stacked Dual Y Chart function addMSLineset($seriesName, $linesetParams){ $this->createLineset(); $this->lineSetCounter++; $this->lineSet[$this->lineCounter][$this->lineSetCounter]= array(); $seriesName=$this->encodeSpecialChars($seriesName); $tempParam=""; $tempParam ="seriesName='" . $seriesName . "' "; $tempParam .= $this->ConvertParamToXMLAttribute($linesetParams); $this->lineIDCounter++; # Setting lineSetParam array with Parameter set $this->lineSetParam [$this->lineSetCounter]=$tempParam; } # The addMSLinesetData() function adds a line to the lineset function addMSLinesetData($value="",$params="",$vlineParams = "" ){ $strSetXML=""; # Getting parameter set $strSetXML=$this->genSSMSChartDataXML($value,$params,$vlineParams); # Setting paramter to lineSet array $this->lineSet[$this->lineCounter][$this->lineSetCounter][$this->lineIDCounter]=$strSetXML; # Increase lineIDCounter $this->lineIDCounter++; } # The setGridParams() function sets SSGrid Chart's Parameters function setGridParams($gridParams){ $this->setChartMessage($gridParams); } # The addTrendLine() function adds a trendline function addTrendLine($tlineParams){ $listArray=explode($this->del,$tlineParams); foreach ($listArray as $valueArray) { $paramValue=explode("=",$valueArray,2); if($this->validateParam($paramValue)==true){ $this->trendLines[$this->tLineCounter][$paramValue[0]]=$this->encodeSpecialChars($paramValue[1]); } } $this->tLineCounter++; } # The addVTrendLine() function adds a Vertical trendline to supported charts function addVTrendLine($vtlineParams){ $listArray=explode($this->del,$vtlineParams); foreach ($listArray as $valueArray) { $paramValue=explode("=",$valueArray,2); if($this->validateParam($paramValue)==true){ $this->vtrendLines[$this->vtLineCounter][$paramValue[0]]=$this->encodeSpecialChars($paramValue[1]); } } $this->vtLineCounter++; } # The addColors() function adds user-defined colors function addColors($ColorList) { $listArray=explode($this->del, $ColorList); $this->userColorON = true; foreach ($listArray as $valueArray) { $this->UserColor[$this->userColorCounter]=$valueArray; $this->userColorCounter++; } } # The clearUserColor() function removes all user-defined colors function clearUserColor() { $this->userColorON = false; } # The defineStyle() function defines a Charts Style function defineStyle($styleName,$styleType,$styleParams){ $this->styles["definition"]["style"][$this->styleDefCounter]["name"]= $styleName; $this->styles["definition"]["style"][$this->styleDefCounter]["type"]= $styleType; $listArray=explode($this->del,$styleParams); foreach ($listArray as $valueArray) { $paramValue=explode("=",$valueArray,2); if($this->validateParam($paramValue)==true){ $this->styles["definition"]["style"][$this->styleDefCounter][$paramValue[0]]= $this->encodeSpecialChars($paramValue[1]); } } $this->styleDefCounter++; } # The applyStyle() function applies a define style to chart elements function applyStyle($toObject,$styles){ $this->styles["application"]["apply"][$this->styleAppCounter]["toObject"]= $toObject; $this->styles["application"]["apply"][$this->styleAppCounter]["styles"]= $styles; $this->styleAppCounter++; } # The function addCategoryFromArray() adds Category from Array function addCategoryFromArray($categoryArray){ # Iterate through each category in the array foreach ($categoryArray as $value) { # Add category $this->addCategory($value); } } # The function addChartDataFromArray() creates dataset values(set) and category, from array function addChartDataFromArray($dataArray, $dataCatArray=""){ if(is_array($dataArray)){ if ($this->seriesType==1){ # Array for Single series charts # aa[..][..]="label" aa[..][..]="Value" foreach($dataArray as $arrayvalue){ if(is_array($arrayvalue)){ $this->addChartData($arrayvalue[1],"label=" . $arrayvalue[0] ); } } }else{ # Array for Multi series charts if(is_array($dataCatArray)){ foreach($dataCatArray as $value){ # Add category $this->addCategory($value); } } # Add data to the chart by creating Datasets foreach($dataArray as $arrayvalue){ if(is_array($arrayvalue)){ $i=0; $aaa[0]=""; $aaa[1]=""; foreach($arrayvalue as $value){ if($i>=2){ $this->addChartData($value); }else{ $aaa[$i]=$value; } if($i==1){ $this->addDataset($aaa[0],$aaa[1]); } $i++; } } } } } } # Database type set like ORACLE and MYSQL function setDataBaseType($dbType){ $this->DataBaseType=strtolower($dbType); } # The addCategoryFromDatabase() function adds Category from database - # by Default from MYSQL recordset. You can use setDatabaseType() function - # to set the type of database. function addCategoryFromDatabase($query_result, $categoryColumn){ if($this->DataBaseType=="mysql"){ # fetch recordset till end of file is reached while($row = mysql_fetch_array($query_result)){ # add category $this->addCategory($row[$categoryColumn],"","" ); } }elseif($this->DataBaseType=="oracle"){ # Fetch recordset till end of file is reached while(OCIFetchInto($query_result, $row, OCI_ASSOC)){ # addcategory() function adds the category $this->addCategory($row[$categoryColumn],"","" ); } } } # The addDataFromDatabase() function adds single series data from database - # by default from MYSQL recordset. You can use setDatabaseType() function - # to set the type of database to work on. function addDataFromDatabase($query_result, $db_field_ChartData,$db_field_CategoryNames="", $strParam="",$link=""){ $paramset=""; if($this->DataBaseType=="mysql"){ # fetching recordset while($row = mysql_fetch_array($query_result)){ if($link==""){ $paramset=""; }else{ # Get the link $paramset="link=" . urlencode($this->getLinkFromPattern($row,$link)); } if ($strParam=""){ $strParam=$paramset; }else{ $strParam .= $this->del . $paramset; } # Convert to set element and save to $partXML if($db_field_CategoryNames==""){ $data=@$row[$db_field_ChartData]; if($strParam!="") $this->addChartData($this->encodeSpecialChars($data),$strParam); else $this->addChartData($this->encodeSpecialChars($data)); } else{ $data=@$row[$db_field_ChartData]; $label=@$row[$db_field_CategoryNames]; $this->addChartData($this->encodeSpecialChars($data),"label=" . $this->encodeSpecialChars($label) . $this->del .$strParam,"" ); } } }elseif($this->DataBaseType=="oracle"){ # fetching recordset while(OCIFetchInto($query_result, $row, OCI_ASSOC)){ if($link==""){ $paramset=""; }else{ # Getting link $paramset="link=" . urlencode($this->getLinkFromPattern($row,$link)); } if ($strParam=""){ $strParam=$paramset; }else{ $strParam .= $this->del . $paramset; } # Convert to set element and save to $partXML if($db_field_CategoryNames==""){ $data=@$row[$db_field_ChartData]; if($strParam!="") $this->addChartData($this->encodeSpecialChars($data),$strParam); else $this->addChartData($this->encodeSpecialChars($data)); } else{ $data=@$row[$db_field_ChartData]; $label=@$row[$db_field_CategoryNames]; $this->addChartData($this->encodeSpecialChars($data),"label=" . $this->encodeSpecialChars($label) . $this->del .$strParam,"" ); } } } } # The addDatasetsFromDatabase() function adds dataset and set elements from - # database, by Default, from MySql recordset. You can use setDatabaseType() function - # to set the type of database to work on. function addDatasetsFromDatabase($query_result, $ctrlField, $valueField,$datsetParamArray="",$link=""){ # Initialize variables $paramset=""; $tempContrl=""; if(is_array($datsetParamArray)==false){ $datsetParamArray=array(); } # Calculate total no of array elements in datsetParamArray $arrLimit=count($datsetParamArray); $i=1; $tempParam=""; if($this->DataBaseType=="mysql"){ ##### For My SQL Connection $FieldArray=explode($this->del,$valueField); if(count($FieldArray)>1){ ### Muli Series # fetching recordset while($row = mysql_fetch_array($query_result)){ # Add Category $this->addCategory($row[$ctrlField]); } $k=0; # Add daatset for multiple fields foreach ($FieldArray as $FieldName) { if($k<$arrLimit){ $tempParam = $datsetParamArray[$k]; }else{ $tempParam=""; } # Add Dataset with adddataset() function $this->addDataset($FieldName,$tempParam); # rewind query result mysql_data_seek($query_result,0); while($row = mysql_fetch_array($query_result)){ # Generating URL link if($link==""){ $paramset=""; }else{ # Generating URL link from getLinkFromPattern $paramset="link=" . urlencode($this->getLinkFromPattern($row,$link)); } # add value to dataset $this->addChartData($row[$FieldName], $paramset, ""); } $k++; } }else{ ### Single Series # fetching recordset while($row = mysql_fetch_array($query_result)){ # Creating Control break depending on ctrlField # if ctrlField value changes then dataset will be Generated if ($tempContrl!=$row[$ctrlField]){ if($i<=$arrLimit){ $tempParam = $datsetParamArray[$i-1]; }else{ $tempParam=""; } # Add Dataset with adddataset() function $this->addDataset($row[$ctrlField],$tempParam); $tempContrl=$row[$ctrlField]; $i++; } # Generating URL link if($link==""){ $paramset=""; }else{ # Generating URL link from getLinkFromPattern $paramset="link=" . urlencode($this->getLinkFromPattern($row,$link)); } # add value to dataset $this->addChartData($row[$valueField], $paramset, ""); } } }elseif($this->DataBaseType=="oracle"){ # For Oracle Connection # fetching recordset while(OCIFetchInto($query_result, $row, OCI_ASSOC)){ # Create Control break depending on ctrlField # if ctrlField value changes then dataset will be Generated if ($tempContrl!=$row[$ctrlField]){ if($i<=$arrLimit){ $tempParam = $datsetParamArray[$i-1]; }else{ $tempParam=""; } # add Dataset $this->addDataset($row[$ctrlField],$tempParam); $tempContrl=$row[$ctrlField]; $i++; } # Generating URL link if($link==""){ $paramset=""; }else{ # Generating URL link from getLinkFromPattern $paramset="link=" . urlencode($this->getLinkFromPattern($row,$link)); } # add value to dataset $this->addChartData($row[$valueField], $paramset, ""); } } } # Set SWF to Transparent function setwMode($isTransparent=""){ $this->wMode=$isTransparent; } # The getXML() function renders final chart XML and returns it function getXML(){ $this->strXML=""; # Call the getChartParamsXML() function to get chart parameter XML $strChartParam=""; $strChartParam=$this->getChartParamsXML(); if($this->seriesType==1){ # Addtional setting for Single Series Line chart if(gettype(strpos($this->chartType,"line"))!="boolean"){ if(strpos($strChartParam,"lineColor")===false){ $colorSet=$this->getColor(0); $this->setChartParams("lineColor=" . $colorSet ); } } # Addtional setting for Single Series Area chart if(gettype(strpos($this->chartType,"area"))!="boolean"){ if(strpos($strChartParam,"areaBgColor")===false){ $colorSet=$this->getColor(0); $this->setChartParams("areaBgColor=" . $colorSet ); } } } # Open Chart element $this->strXML = "getChartParamsXML() . " >"; # call getCategoriesXML() function to generate category XML elements $this->strXML .= $this->getCategoriesXML(); # call getDatasetXML() function to generate chart's dataset XML elements $this->strXML .= $this->getDatasetXML(); # call getvTrendLinesXML() function to generate vTrendLines XML elements if($this->seriesType==3){ $this->strXML .= $this->getvTrendLinesXML(); } # Call getLinesetXML() function to generate lineSet XML elements if($this->seriesType==4){ $this->strXML .= $this->getLinesetXML(); } # call getTrendLinesXML() function to generate TrendLines XML elements $this->strXML .= $this->getTrendLinesXML(); # call getStylesXML() function to generate styles elements $this->strXML .= $this->getStylesXML(); # Close Chart element $this->strXML .= ""; # Return XML output return $this->strXML; } # The function setChartMessage() sets the message to display on the chart function setChartMessage($msgParam){ if($this->chartMSG==""){ $this->chartMSG="?"; }else{ $this->chartMSG .= "&"; } $strParamCol=""; $strParamCol=$this->ConvertParamToXMLAttribute($msgParam, true); $this->chartMSG .= $strParamCol; } # The setOffChartCaching() function sets whether chart SWF files are not to be cached function setOffChartCaching($swfNoCache=false){ $this->noCache=$swfNoCache; } # The renderChart() function generates the chart function renderChart($renderAsHTML=false, $display=true){ $this->strXML=$this->getXML(); $this->SWFFile=$this->SWFPath . $this->chartSWF[$this->chartType][0] . ".swf"; # Stop chart caching if required if($this->noCache==true){ if($this->chartMSG==""){ $this->chartMSG = "?nocache=" . microtime(); }else{ $this->chartMSG .= "&nocache=" . microtime(); } } # render chart using RenderAsHTML option if($renderAsHTML==true){ if($display==true){ # true: render using html embedding method print $this->renderChartHTML($this->SWFFile . $this->chartMSG ,"", $this->strXML, $this->chartID, $this->width, $this->height, $this->JSC["debugmode"], $this->JSC["registerwithjs"], $this->wMode); }else{ # true: render using html embedding method return $this->renderChartHTML($this->SWFFile . $this->chartMSG ,"", $this->strXML, $this->chartID, $this->width, $this->height, $this->JSC["debugmode"], $this->JSC["registerwithjs"], $this->wMode); } }else{ if($display==true){ # false: render using JavaScript embedding method print $this->renderChartJS($this->SWFFile . $this->chartMSG ,"", $this->strXML, $this->chartID, $this->width, $this->height, $this->JSC["debugmode"], $this->JSC["registerwithjs"], $this->wMode); return true; }else{ # false: render using JavaScript embedding method return $this->renderChartJS($this->SWFFile . $this->chartMSG ,"", $this->strXML, $this->chartID, $this->width, $this->height, $this->JSC["debugmode"], $this->JSC["registerwithjs"], $this->wMode); } } } # The renderChartFromExtXML() function renders Chart form External XML (string) function renderChartFromExtXML($dataXML,$renderAsHTML=false){ # Print the HTML chart if($renderAsHTML==true){ print $this->renderChartHTML($this->SWFFile . $this->chartMSG ,"", $dataXML, $this->chartID, $this->width, $this->height, $this->JSC["debugmode"], $this->JSC["registerwithjs"], $this->wMode); }else{ print $this->renderChartJS($this->SWFFile,"",$dataXML,$this->chartID, $this->width, $this->height,$this->JSC["debugmode"], $this->JSC["registerwithjs"], $this->wMode); } } # The renderChartFromExtData() function renders Chart form External data (string) function renderChartFromExtData($data, $dataformat="xml",$renderAsHTML=false) { # Print the HTML chart if($renderAsHTML==true) { print $this->renderChartHTML($this->SWFFile . $this->chartMSG ,"", $data, $this->chartID, $this->width, $this->height, $this->JSC["debugmode"], $this->JSC["registerwithjs"], $this->wMode); } else { $this->setDataFormat($dataformat); print $this->renderChartJS($this->SWFFile,"",$data,$this->chartID, $this->width, $this->height,$this->JSC["debugmode"], $this->JSC["registerwithjs"], $this->wMode); } } #The function SetInitParam() adds extra chart settings function setInitParam($tname,$tvalue){ $trimName= strtolower(str_replace(" ","",$tname)); $this->JSC[$trimName]=$tvalue; } ##------------ PRIVATE FUNCTIONS ------------------------------------------------------ # The function getDatasetXML() returns xml for the chart from the .... function getDatasetXML(){ # Calling dataset function depending on seriesType switch ($this->seriesType){ case 1 : return $this->getSSDatasetXML(); break; case 2 : return $this->getMSDatasetXML(); break; case 3 : return $this->getMSDatasetXML(); break; case 4 : return $this->getMSStackedDatasetXML(); break; } } # By getChartParamsXML() function, we can fetch charts array and convert into XML - # and return like "caption='xyz' xAxisName='x side' ............ function getChartParamsXML(){ $partXML=""; # Fetching charts each array and converting into chart parameter foreach($this->chartParams as $part_type => $part_name){ $partXML .= $part_type . "='" . $this->encodeSpecialChars($part_name) . "' "; } # Return Chart Parameter return $partXML; } # The function getCategoriesXML() for getting Category part XML function getCategoriesXML(){ if($this->seriesType>1){ $partXML=""; # Add categories parameter $partXML="categoriesParam . " >"; if($this->categoryNamesCounter>1){ foreach($this->categoryNames as $part_type => $part_name){ if($part_name!=""){ # add elements if($part_name!="Array"){ $partXML .= $part_name; } } } } # Closing $partXML .=""; return $partXML; } } # Create single set element # # function getSSDatasetXML(){ if($this->seriesType==1){ $partXML=""; foreach($this->dataset as $part_type => $part_name){ if($part_name!=""){ # Add elements if($part_name!="Array"){ $partXML .= $part_name; } } } return $partXML; } } # getMSDatasetXML for getting datset part XML # # # # function getMSDatasetXML(){ if($this->seriesType>1){ $partXML=""; foreach($this->dataset as $part_type => $part_name){ $partXML .="datasetParam[$part_type] . " >"; foreach($this->dataset[$part_type] as $part_type1 => $part_name1){ if($part_name1!=""){ # Add elements if($part_name1!="Array"){ $partXML .= $part_name1; } } } $partXML .=""; } return $partXML; } } # Function getMSStackedDatasetXML for getting datset part XML from ms stacked chart dataset array # # # # # # function getMSStackedDatasetXML(){ if($this->seriesType==4){ $partXML=""; foreach($this->MSStDataset as $part_type => $part_name){ $partXML .= ""; foreach($this->MSStDataset[$part_type] as $part_type1 => $part_name1){ $partXML .= "MSStDatasetParams[$part_type][$part_type1] . " >"; foreach($this->MSStDataset[$part_type][$part_type1] as $part_type2 => $part_name2){ if ($part_type2!=""){ $partXML .= $part_name2; } } $partXML .= ""; } $partXML .= ""; } return $partXML; } } # The function getLinesetXML() for getting Lineset XML function getLinesetXML(){ # If seriesType MSStackedColumn2DLineDY (4) then Lineset element will be Generated if($this->seriesType==4){ $partXML=""; # Fetching lineSet array and Generating lineset xml element foreach($this->lineSet as $part_type => $part_name){ $partXML .= "lineSetParam[$part_type] . " >"; foreach($this->lineSet[$part_type] as $part_type1 => $part_name1){ foreach($this->lineSet[$part_type][$part_type1] as $part_type2 => $part_name2){ if ($part_type2!=""){ $partXML .= $part_name2; } } } $partXML .= ""; } return $partXML; } } # The function getTrendLinesXML() create XML output depending on trendLines array # # # function getTrendLinesXML(){ $partXML=""; $lineXML=""; # Fetch trendLines array foreach($this->trendLines as $l_type => $l_name){ # Line element $lineXML .="trendLines[$l_type] as $part_type => $part_name){ $lineXML .= $part_type . "='" . $this->encodeSpecialChars($part_name) . "' "; } # Close line element $lineXML .=" />"; } # If line element present, then adding $lineXML within trendLines element $pos = strpos($lineXML, "="); if ($pos!==false){ $partXML = "" . $lineXML . ""; }else{ # Return nothing $partXML=""; } # Return trendLines xml return $partXML; } # The function getvTrendLinesXML() returns XML output depending on trendLines array # # # function getvTrendLinesXML(){ $partXML=""; $lineXML=""; # Fetch vtrendLines array foreach($this->vtrendLines as $l_type => $l_name){ # staring line element $lineXML .="vtrendLines[$l_type] as $part_type => $part_name){ if($part_name!=""){ $lineXML .= $part_type . "='" . $this->encodeSpecialChars($part_name) . "' "; } } # Close line element $lineXML .=" />"; } # If line element present then adding $lineXML with in vtrendLines element $pos = strpos($lineXML, "="); if ($pos !== false) { $partXML = "" . $lineXML . ""; }else{ # Return nothing $partXML=""; } # Return vtrendLines xml return $partXML; } # The function getStylesXML() returns the styles XML from styles array /*