JavaScript global functions |
FusionCharts(chartId: String) |
This function helps in accessing the JavaScript Object reference of a chart. A reference of a chart is necessary to perform all available API functions, use all available properties and listen to events.
When a chart-id is passed, it tries to return (if available) the reference of the instance of the FusionCharts object.
This is same as FusionCharts.items[] static array which also provides the reference of the chart object. |
It returns the chart object reference which you can use to call all API functions, use all API properties and listen to API events.
var chartReference = FusionCharts("myChartId");
|
getChartFromId(chartId: String) |
This function helps in accessing the JavaScript Object reference of a chart. Same as FusionCharts() static function.
getChartFromId is deprecated.
|
It returns the chart object reference which you can use to call all API functions, use all API properties and listen to API events.
var chartReference = getChartFromId("myChartId"); |
|
FusionCharts class - static functions |
getObjectReference(chartId: String) |
This function helps in accessing the HTML Object reference of a chart. HTML Object is the actual chart object that physically gets rendered on the web page. The HTML object helps in direct communication between the chart and JavaScript.
It is not recommended to use this function unless absolutely needed. |
Returns the HTML object that has been rendered. In case of Flash renderer, this will return the reference to the HTML node where the SWF is rendered.
var chartHTMLReference = FusionCharts.getObjectReference("myChartId"); |
setCurrentRenderer(renderer: String) |
Sets the renderer for all the charts. Presently you can pass either 'javascript' or 'flash' as the value of renderer parameter.
All the charts that get rendered, after this function call, will abide by this setting. |
FusionCharts.setCurrentRenderer('javascript'); |
render(chartParameters: Object)
or
render(swfUrl, chartId , width, height, renderAt, dataSource, dataFormat, otherParameters: Object)
or
render(chartParameters: mixed)
or
render(chartObject: FusionCharts)
|
This function acts as a compact constructor for FusionCharts. It is a static function that helps rendering a chart using a single line of code.
It can take an Object as parameter containing all chart parameters. See, first example on right.
It can take linear string parameters (second example on right) as listed below:
- swfUrl : Path to the chart SWF file or
type: JavaScript Chart Alias (to render JavaScript chart) as listed here
- id : DOM id to be set to the chart
- width : Width of the chart
- height : Height of the chart
- renderAt : Container HTML element's (normally a DIV) Id or HTMLNode object where the chart will be rendered
- dataSource : XML or JSON chart data. It can be a URL for XML or JSON, it can be XML or JSON in string or it can be a JSON object
- dataFormat : Defines the format of the dataSource.
- It is xmlurl when data source is a URL to XML data
- It is xml when the data source is an XML String
- It is jsonurl when data source is a URL to JSON data
- It is json when the data source is a JOSN String or JSON object
- otherParameters : It contains other chart parameters. Click here to see detailed list of chart parameters
Additionally, it can take a mixture of linear parameters and an Object parameter at the end. The linear parameters should be in order. You can pass any one or more (up to no. 7 in the list above) linear parameters before you can pass the Object parameter. See the third example on right.
NOTE: You must pass the values for swfUrl, dataSource and dataFormat to render a chart. The chart will fail to render if any one of these parameters are missing.
You may also pass an instance of FusionCharts object to it in order to render each FusionCharts object.
This function fires up the chart rendering processes. Hence, a number of events are fired after this function call. The events are listed in sequence below:
On various issues when chart does not get rendered these error events are fired:
|
It returns a javascript chart object.
Example:
var myChart = FusionCharts.render({ swfUrl : "Charts/Pyramid.swf", id : "myChartId", renderAt : "chartContainer", dataSource : "Data.xml" })
or
var myChart = FusionCharts.render("Charts/Pyramid.swf", "myChartId", "400", "300", "chartContainer", "Data.xml", "xmlurl");
or
var myChart = FusionCharts.render({ type : "Pyramid", id : "myChartId", renderAt : "chartContainer", dataSource : "Data.xml" })
or
var myChart = FusionCharts.render("Pyramid", "myChartId", "400", "300", "chartContainer", {dataFormat : "xmlurl", dataSource : "Data.xml" });
|
addEventListener(event:String, listener: function)
or
addEventListener(events:Array, listener: function) |
This function acts as advanced event registration model. You give it two arguments: the event type or name of the event and the function to be executed.
This function, when called as static method using FusionCharts.addEventListener(), registers the global events of all the charts present in a page.
In the listener argument you can pass a named-function or the name of a function (see example at the top on right column) which will listen to the event or you can directly define an anonymous function as the argument (see example at bottom on the right column).
You may attach a function to multiple events by passing the event names in an array.
|
It returns nothing.
Example:
FusionCharts.addEventListener("Rendered", doSomething);
or
FusionCharts.addEventListener("Rendered", function(e,p) { alert(e.sender.id ); });
or
FusionCharts.addEventListener(['Initialized', 'Disposed'], function () { // do something! });
|
removeEventListener(event:String, listener: function)
or
removeEventListener(events:Array, listener: function) |
This function removes a named event-listener function for a particular event that was defined using addEventListener. This function when called as static method using FusionCharts.removeEventListener() removes a named events-listener from all the charts on a page.
The name of the event type is passed as the first parameter.
The second parameter is the name of the function which was added as the event listener for that event by addEventListener
You may also remove a function from multiple events by passing the event names in an array. |
It returns nothing.
Example:
FusionCharts.removeEventListener("Rendered", doSomething);
|
|
FusionCharts class - constructor |
FusionCharts |
This is the constructor method of FusionCharts JavaScript Class. It allows you to create new instance of FusionCharts using legacy set of linear parameters as well as an Object parameter.
It can take an Object as parameter containing all chart parameters. See, first example on right.
Chart Parameters
It can take linear string parameters (second example on right) as listed below:
- swfUrl : Path to the chart SWF file or
type: JavaScript Chart Alias (to render JavaScript chart) as listed here
- id : DOM id to be set to the chart (optional)
- width : Width of the chart (optional - default is 400)
- height : Height of the chart (optional - default is 300)
- debugMode : Sets the chart debug window on. Can take "0" or "1". "1" sets debug window on. (optional - default value is "0")
- registerWithJS : Allow chart to communicate with JavaScript. This should be set to "1". This parameter is deprecated and is kept for backward compatibility issues. (optional)
- bgColor : A String containing hex coded color value. This sets the color of the Flash player's background on which a chart gets drawn. This background color is not same as the background color of a chart. This background is visible while showing chart messages or when chart's bgAlpha is set to less than 100. (optional - default value is "#FFFFFF" i.e., white)
- scaleMode : Flash player's mode of scaling a chart. "NoScale" should be the value. There are other options like showAll, ExactFit, noBorder. But these are not supported and might result into distorted charts.
(optional)
- lang :Sets the language. It presently supports English only. The value is "EN". (optional)
- detectFlashVersion :Set to "1" to make FusionCharts Class check whether Flash Player 8 is present in the Browser. (optional - Default value is "0' )
- autoInstallRedirect :Set to "1" with detectFlashVersion set to "1" and FusionCharts redirects to Flash Player installation page of Adobe's Web site. (optional - default is "0')
Apart from these parameters you can add additional parameters to the object based parameter. Those additional parameters are :
- renderAt : Container HTML element's (normally a DIV) Id or HTMLNode object where the chart will be rendered
- dataSource : XML or JSON chart data. It can be a URL for XML or JSON, it can be XML or JSON in string or it can be a JSON object
- dataFormat : Defines the format of the dataSource.
- It is xmlurl when data source is a URL to XML data
- It is xml when the data source is an XML String
- It is jsonurl when data source is a URL to JSON data
- It is json when the data source is a JOSN String or JSON object
- renderer : Sets the chart renderer engine. Its value can be 'flash' or 'javascript'. The default value is flash which generated Flash based charts. When set to javascript FusionCharts JavaScript Class renders pure JavaScript based charts.
Additionally, it can take a mixture of linear parameters and an Object parameter at the end. The linear parameters should be in order. You can pass any one or more (up to no. 11 in the list above) linear parameters before you can pass the Object parameter. See the third example on right.
After instantiating the object, Initialized event will get fired.
|
It returns a javascript chart object.
Example:
var myChart = new FusionCharts({ swfUrl : "Charts/Pyramid.swf", id : "myChartId", renderAt : "chartContainer", dataSource : "Data.xml" });
or
var myChart = new FusionCharts("Charts/Pyramid.swf", "myChartId", "400", "300");
or
var myChart = new FusionCharts("Charts/Pyramid.swf", "myChartId", "400", "300", "chartContainer", {dataFormat : "xmlurl", dataSource : "Data.xml"});
or
var myChart = new FusionCharts({ type : "Pyramid.swf", id : "myChartId", renderAt : "chartContainer", dataSource : "Data.xml" });
or
var myChart = new FusionCharts("Pyramid", "myChartId", "400", "300");
or
var myChart = new FusionCharts("Pyramid", "myChartId", "400", "300", "chartContainer", {dataFormat : "xmlurl", dataSource : "Data.xml"});
|
|
FusionCharts class - instance functions |
configure(name:String , value:String)
or
configure(configurations: Object) |
Sets a chart configuration before rendering the chart. You can mainly use this function to set chart messages.
The name of the configuration and the value of the configuration are passed as parameters. See first example on the right.
You can also pass a collection of configurations as Object to the function. The parameter object will contain name and value pairs of the configuration name and the corresponding values. See second example on the right.
|
myChart.configure("ChartNoDataText", "Please select a record above");
or
myChart.configure({ "ChartNoDataText" : "Please select a record above" , "InvalidXMLText" : "Please validate data" }); |
addVariable(name:String , value:String)
|
Sets a chart configuration before rendering the chart. You can mainly use this function to set chart messages or grid parameters using this function.
addVariable is deprecated.
|
myChart.addVariable("ChartNoDataText", "Please select a record above"); |
render(renderAt: String)
or
render(renderAt: HTMLNode) |
This function renders a chart inside a container element reference to which has passed as a parameter of this function.
This function is called after the chart gets instantiated as JavaScript object new FusionCharts. It takes a string containing the id of an HTML container Element like DIV or SPAN.
You can also pass the HTMLNode object of a container element to this function.
This function fires the chart rendering process. Hence, a number of events are fired after this function call. The events are listed in sequence below:
On various issues when chart does not get rendered these error events are fired:
|
myChart.render("chartContainer");
or
myChart.render(document.getElementById ("chartContainer")); |
setTransparent ( isTransparent: Boolean ) |
Makes the chart background ready to become transparent. You need to set bgAlpha, canvasBgAlpha etc. attributes of the <chart> element to finalize the transparency.
The function accepts a boolean parameter. Only when true is passed by the chart to the function, the chart is prepared to have transparent background.
|
myChart.setDataXML( "<chart bgAlpha='0,0'><set value='213' /></chart>");
myChart.setTransparent(true);
|
setXMLUrl(Url: String) |
Sets or changes the XML data of the chart to a specified URL. The URL has to be relative to the web page where the chart is deployed. By default, cross-domain URL-s are not allowed. Again, absolute URL-s are not allowed. |
myChart.setXMLUrl("mychartdata.xml");
|
setXMLData(XML: String) |
Changes the data of the chart to the specified XML string.
Note of caution: When specifying XML as string, please make sure that there are no conflicts in quotes between the JS function call and the quotation mark used to enclose attributes in XML string. |
myChart.setXMLData("<chart><set value='100' /></chart>");
|
setJSONUrl(Url: String) |
Sets or changes the data of the chart to a specified URL. The URL has to be relative to the web page where the chart is deployed. By default, cross-domain URL-s are not allowed. Again, absolute URL-s are not allowed. |
myChart.setJSONUrl("myJSONStream.json");
|
setJSONData(JSON:Object)
or
setJSONData(JSON:String) |
Changes the data of the chart to the specified JSON string or JSON Object.
Note of caution: When specifying JOSN as string, please make sure that there are no conflicts in quotes between the JS function call and the quotation mark used to enclose JSON properties and values. |
myChart.setJSONData( {
"chart":{
"caption":"My Chart Caption"
},
"data":[
{ "value":"100" },
{ "value":"200" }
]
}
);
or
myChart.setJSONData('{"chart":{ "caption":"My Chart Caption" }, "data":[ {"value":"100" }, { "value":"200" } ] });
|
setChartDataUrl(Url:String, dataFormat: String) |
Sets or changes the data of the chart to a specified URL. The URL has to be relative to the web page where the chart is deployed. By default, cross-domain URL-s are not allowed. Again, absolute URL-s are not allowed.
This function takes two parameters. The first is URL of the data. The second is the dataFormat in string, which can be "xml" or "json". |
myChart.setChartDataUrl("mydynamicdata.aspx", "json");
or
myChart.setChartDataUrl("mydynamicdata.aspx", "xml");
|
setChartData(dataSource: String, dataFormat: String) |
Sets or changes the data of the chart.
This function takes two parameters. The first is dataSource of the data. The second is the dataFormat. The data source can be a URL to XML source, URL to JSON source, XML as string, JSON as string and JSON as object. Hence, to identify the format correctly, dataFormat is passed as the second parameter.
dataFormat : Defines the format of the dataSource.
- It is xmlurl when data source is a URL to XML data
- It is xml when the data source is an XML String
- It is jsonurl when data source is a URL to JSON data
- It is json when the data source is a JOSN String or JSON object
|
myChart.setChartData( "myxmldata.jsp" , "xmlurl");
or
myChart.setChartData( "<chart><set value='2310'/></chart>" , "xml");
or
myChart.setChartData( "myjsondata.php" , "jsonurl");
or
myChart.setChartData( "{ chart : {}, data :[{ value : 100 }] }" , "json");
or
myChart.setChartData( { chart : {}, data :[{ value : 100 }] } , "json");
|
setDataURL(Url:String) |
This function helps in setting or updating chart XML data for chart from URL. This function takes a URL as string.
setDataURL is deprecated.
|
myChart.setDataURL( "myxmlsource.xml" );
|
setDataXML(dataSource: String) |
This function helps in setting or updating chart XML data for a string.
setDataXML is deprecated.
|
myChart.setDataXML( "<chart><set value='213' /></chart>");
|
getChartData(dataFormat:String) |
This function returns chart data as per dataFormat provided as parameter. When xml is passed as dataFormat it provides XML data as string. When json is passed as dataFormat, data is returned as JSON Object. |
var myXML = FusionCharts("myChartId").getChartData( "xml");
var myJSONObj = FusionCharts("myChartId").getChartData( "json" );
|
getXMLData()
|
Returns the XML data of chart as string.
|
var myXML = FusionCharts("myChartId").getXMLData();
|
getJSONData() |
Returns the JSON data of chart as Object.
|
var myJSONObj = FusionCharts("myChartId").getJSONData();
|
getDataAsCSV() |
Returns the data of chart as CSV string. The output CSV string can be configured using XML parameters. String representing data of chart in CSV format. |
var strCSV = FusionCharts("myChartId").getDataAsCSV();
|
getXML() |
Returns the XML data of chart.
Note: getXML is deprecated.
|
var myXML = FusionCharts("myChartId").getXML();
|
getChartAttribute() |
Returns the value of the attribute as specified in chart XML Node or "chart" property of JSON data.
Value of the attribute; or "null" if the attribute was empty or not found in XML/JSON. |
var caption = FusionCharts("myChartId").getChartAttribute( "caption");
|
setChartAttribute(name:String, value:String)
or
setChartAttribute(AttributeCollection:Object)
|
Sets chart attribute and update the chart with the new value. It takes two parameters. The name of the attribute and the value of the parameter.
The name suggests chart's root properties (also known as "chart attributes" which are passed through <chart> element in chart XML data or through the chart property in chart's JSON data).
You can also pass a collection of attribute name and value pairs to the function by passing them as an Object. See second example on the right.
Once chart attributes get changed the drawcomplete event is fired.
In case you wish to remove an attribute from the data you can pass null as the value of the attribute. e.g., setChartAttribute( "palette" , null ) will remove the palette attribute from the data.
|
myChart.setChartAttribute ( "caption" , "Latest sales report" );
or
chartReference.setChartAttribute( { "palette" : "2", paletteColors : "ACBF72", useRoundEdges : 1 } ); |
configureLink(objConfiguration: Object, level:Number)
or
configureLink(arrConfiguration: Array) |
Through this function you can pass all your desired configurations for the LinkedCharts. You can pass all the properties that a FusionCharts constructor function accepts. Those chart properties will be applied to the LinkedCharts. If not provided, the LinkedCharts will inherit properties from the parent chart.
Additionally, you can also configure the overlay button using the overlayButton property. These settings also go as another object.
The configureLink function can accept parameters in either of two formats :
- As two separate parameters, the first parameter is an Object containing all configurations (chart and overlayButton). The second parameter accepts a number which denotes the level being configured. The first drill-down level is 0 (zero). See example at the top on the right.
- As a single dimensional indexed array each element of which is an object containing all chart and overlay button related configurations. Each drill-down level is denoted by the index of the array where the first level is Zero. So, the Object in a particular array index actually applies those settings to the level number which is equal to array index number. See example at the bottom on the right.
Overlay Button settings:
The following are the properties that we can pass as settings for overlay buttons:
- show : (true/false) whether to show the overlay button
- message: String contain the text for close button
- bgColor: Hex coded background color of the overlay button
- borderColor: Hex coded border color of the overlay button
- font : Name of the font
- fontColor : Hex coded color of the overlay button's text
- fontSize : Size of the font of overlay button text
- bold : (true/false) Whether the overlay button's text will be bold
- padding :padding around the overlay button in pixels
|
myChart.configureLink(
{
swfUrl: 'Charts/Pyramid.swf',
width: '30%',
overlayButton:
{
message: ' x ',
bgColor:'999999',
borderColor: 'cccccc'
}
},
0);
myChart.configureLink(
[ {swfUrl: 'Charts/Pyramid.swf'},
{swfUrl: 'Charts/Funnel.swf'},
{swfUrl: 'Charts/SparkLine.swf'},
{swfUrl: 'Charts/SparkColumn.swf'}
]
);
|
resizeTo(width:String, height:String) |
This function resizes an existing chart. You can pass the width and height values in percentage or as pixel values (without the px suffix).
Once a chart gets resized, the resized (FC_Resized), and the drawcomplete events are fired. |
myChart.resizeTo( "500", "400" )
or
myChart.resizeTo( "80%", "100%" ) |
exportChart( exportSettings: Object) |
Calls the export chart routine to save the chart as PDF/image. exportSettings object here contains over-riding parameters to over-ride the export parameters initially specified in XML. For more information read this.
In cases, while saving a chart to a server location, a callback function is invoked to convey status of export. |
myChart.exportChart( { exportFormat : 'jpg'} ) |
print() |
Prints a chart.
|
FusionCharts("myChartId").print()
|
clone( [chartParams: Object] ) |
The function allows you to duplicate a FusionCharts JavaScript object and uses it's settings to create another chart.
The function can optionally take an object as parameter. The object can contain chart settings which will override the existing settings of the source chart before it gets cloned.
The function returns an instance of FusionCharts JavaScript object. |
var newChart = myChart.clone();
or
var newChart = myChart.clone( { swfUrl : 'Cylinder.swf' } );
|
dispose() |
You can remove a chart instance from page and memory using the dispose() function.
Additionally, the function will raise the BeforeDispose event prior to removing a chart and the disposed event after the chart has been removed. |
FusionCharts("myChartId").dispose();
|
chartType() |
This function returns the chart type or chart alias of the rendered by the FusionCharts JavaScript object.
Please note that the alias value is dependent on the chart SWF file-name. The alias is built removing .swf extension and all extra path information from the src value of the chart loaded. |
var strCharType = FusionCharts("myChartId").chartType();
|
isActive() |
This function checks whether a FusionCharts SWF is visible and active. Returns true or false. |
var strCharType = FusionCharts("myChartId").isActive();
|
hasRendered() |
This function returns Boolean value indicating whether the chart has finished rendering.
hasRendered() is deprecated
|
var strCharType = FusionCharts("myChartId").hasRendered();
|
signature() |
It returns a string representing the signature of chart. For FusionWidgets XT charts, it's "FusionWidgets/3.2 (XT)" |
var strCharType = FusionCharts("myChartId").signature();
|
|
FusionCharts.printManager class - static functions |
configure(configuration: Object)
Note: Print Manager works only in browsers that supports canvas object.
|
This function configures the print Manager. It takes an Object. In this object you can pass two properties:
enabled and message.
This function needs to be called before you call FusionCharts.printManager.enabled()
The enabled property sets the Print Manager on or off by setting the value to true or false, respectively.
The message property takes a string which gets displayed in place of the printable charts until the charts are prepared for printing. The default value is : 'Chart is being prepared for print.'
|
FusionCharts.printManager.configure( { enabled: true, message : 'wait please...'} );
|
enabled (on: Boolean)
Note: Print Manager works only in browsers that supports canvas object.
|
This function initializes the print manager if true is passed as the parameter. Once this function is called, the print manager starts preparing all the charts in a page for managed print. |
FusionCharts.printManager.enabled(true);
|
managedPrint() |
Prints the chart once the print manager completes its process of making the chart ready for managed print. After the function has been called, it waits till the charts become ready. |
FusionCharts.printManager.managedPrint();
|
isReady() |
Returns true when the print manger has completed the process of making all charts in a page ready for print. |
var goPrint = FusionCharts.printManager.isReady();
|
|
FusionCharts.debugMode class - static functions |
outputTo(outputFunction: function) |
Function that will handle all debug output. Generally, console.log is used in browsers supporting console. You can also use alert when setting text as outputFormat.
This function needs to be called before you call FusionCharts.debugMode.enabled() |
FusionCharts.debugMode.outputTo(console.log); |
outputFormat(outputFormat: String) |
The supported debugMode output formats are: text (default), verbose and event.
This function needs to be called before you call FusionCharts.debugMode.enabled()
When the outputFormat is set to event, the output function assigned to the debugger (using debugMode method) is sent arguments exactly matching FusionCharts Advanced events model. |
FusionCharts.debugMode.outputFormat('verbose'); |
enabled(isEnabled:Boolean)
or
enabled(outputFunction:function, outputFormat:String)
|
Enables FusionCharts JavaScript debugMode.
Note that FusionCharts JavaScript debugMode works independent of the debugMode (debug window) that individual Flash based charts offer.
While using a single parameter you need to pass true to enable the debugMode.
You can use a compact format which sets output function, as well as output format and enables debugMode by passing two parameters. Here, the first parameter will be the outputFunction and the second parameter will be the outputFormat.
|
FusionCharts.debugMode.enabled(true);
or
FusionCharts.debugMode.enabled(console.log, 'verbose'); |