JavaScript global functions |
FusionCharts(chartId: string) |
This function helps in accessing the JavaScript Object reference of a map . A reference of a map is necessary to perform all available API functions, use all available properties and listen to events.
When a map-id is passed, it tries to return (if available) the reference of the instance of the FusionCharts object.
This is same as the FusionCharts.items[] static array which also provides the reference of the map object. |
It returns the map object reference which you can use to call all API functions, use all API properties, and listen to API events.
var mapReference = FusionCharts("myMapId");
|
getMapFromId(chartId: string) |
This function helps in accessing the JavaScript Object reference of a map. Same as FusionCharts() static function.
getMapFromId is deprecated.
|
It returns the map object reference which you can use to call all API functions, use all API properties and listen to API events.
var mapReference = getMapFromId("myMapId"); |
|
FusionCharts Class - static functions |
getObjectReference(chartId: string) |
This function helps in accessing the HTML Object reference of a map. HTML Object is the actual map object that physically gets rendered on the web page. The HTML object helps in direct communication between the map 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("myMapId"); |
setCurrentRenderer(renderer: string) |
Sets the renderer for all the maps. Presently you can pass either 'javascript' or 'flash' as the value of renderer parameter.
All the maps 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 map using a single line of code.
It can take an Object as parameter containing all map parameters. See, first example on right.
It can take linear string parameters (second example on right) as listed below:
- swfUrl : Path to the map SWF file or type: JavaScript Map Alias (to render JavaScript map) as listed here
- id : DOM id to be set to the map
- width : Width of the map
- height : Height of the map
- renderAt : Container HTML element's (normally a DIV) Id or HTMLNode object where the chart will be rendered
- dataSource : XML or JSON map 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 JSON String or JSON object
- otherParameters : It contains other map parameters. Click here to see detailed list of map 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/type, dataSource and dataFormat to render a map. The map 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 map rendering processes. Hence, a number of events are fired after this function call. The events are listed in sequence below:
On various issues when map does not get rendered these error events are fired:
|
It returns a javascript chart object.
Example:
var myMap = FusionCharts.render({ swfUrl : "Maps/FCMap_World.swf", id : "myMapId", renderAt : "mapContainer", dataSource : "Data.xml" })
or
var myMap = FusionCharts.render("Maps/FCMap_World.swf", "myMapId", "400", "300", "mapContainer", "Data.xml", "xmlurl");
or
var myMap = FusionCharts.render("Maps/FCMap_World.swf", "myMapId", "400", "300", "mapContainer", {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 maps 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 maps 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 map parameters. See, first example on right.
Map Parameters
It can take linear string parameters (second example on right) as listed below:
- swfUrl: Path to the map SWF file or type: JavaScript Map Alias (to render JavaScript map) as listed here
- id: DOM id to be set to the map (optional)
- width: Width of the map (optional - default is 400)
- height: Height of the map (optional - default is 300)
- debugMode: Sets the map debug window on. Can take "0" or "1". "1" sets debug window on. (optional - default value is "0")
- registerWithJS: Allow map to communicate with JavaScript. This should be set to "1". This parameter is deprecated and is kept to take care 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 map gets drawn. This background color is not same as the background color of a map. This background is visible while showing map messages or when map's bgAlpha is set to less than 100. (optional - default value is "#FFFFFF", that is, white)
- scaleMode: Flash player's mode of scaling a map. "NoScale" should be the value. There are other options like showAll, ExactFit, noBorder. But these are not supported and might result into distorted maps.
(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 parameter 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 map will be rendered
- dataSource: XML or JSON map 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 JSON String or JSON object
- renderer: Sets the map renderer engine. Its value can be 'flash' or 'javascript'. The default value is flash which generated Flash based maps. When set to javascript FusionCharts JavaScript Class renders pure JavaScript based maps.
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 map object.
Example:
var myMap = new FusionCharts({ swfUrl : "Maps/FCMap_World.swf", id : "myMapId", renderAt : "mapContainer", dataSource : "Data.xml" });
or
var myMap = new FusionCharts("Maps/FCMap_World.swf", "myMapId", "400", "300");
or
var myMap = new FusionCharts("World", "myMapId", "400", "300");
or
var myMap = new FusionCharts({ type : "World", id : "myMapId", renderAt : "mapContainer", dataSource : "Data.xml" });
|
|
FusionCharts class - instance functions |
configure(name:string , value:string)
or
configure(configurations: Object) |
Sets a map configuration before rendering the map. You can mainly use this function to set map messages using this function.
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.
|
myMap.configure("ParsingDataText", "Please select a record above");
or
myMap.configure({ "ParsingDataText" : "Please select a record above" , "InvalidXMLText" : "Please validate data" }); |
addVariable(name:string , value:string)
|
Sets a map configuration before rendering the map. You can mainly use this function to set map messages or grid parameters using this function.
addVariable is deprecated.
|
myMap.addVariable("ParsingDataText", "Please select a record above"); |
render(renderAt: String)
or
render(renderAt: HTMLNode) |
This function renders a map inside a container element reference to which has passed as a parameter of this function.
This function is called after the map 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 map rendering process. Hence, a number of events are fired after this function call. The events are listed in sequence below:
On various issues when map does not get rendered these error events are fired:
|
myMap.render("mapContainer");
or
myMap.render(document.getElementById ("mapContainer")); |
setXMLUrl(URL: String) |
Sets or changes the XML data of the map to a specified URL. The URL has to be relative to the web page where the map is deployed. By default, cross-domain URLs are not allowed. Again, absolute URLs are not allowed. |
myMap.setXMLUrl("mychartdata.xml");
|
setXMLData(XML: string) |
Changes the data of the map 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. |
myMap.setXMLData("<map><set value='100' /></map>");
|
setJSONUrl(URL: String) |
Sets or changes the data of the map to a specified URL. The URL has to be relative to the web page where the map is deployed. By default, cross-domain URLs are not allowed. Again, absolute URLs are not allowed. |
myMap.setJSONUrl("myJSONStream.json");
|
setJSONData(JSON:Object)
or
setJSONData(JSON:String) |
Changes the data of the map to the specified JSON string or JSON Object.
Note of caution: When specifying JSON 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. |
myMap.setJSONData( {
"map":{
"numberPrefix":"$"
},
"data":[
{ "id": "AL", "value": "70" },
{ "id": "AK", "value": "100" },
{ "id": "AZ", "value": "90" },
{ "id": "AR", "value": "72" }
]
}
);
or
myMap.setJSONData('{"map":{ "numberPrefix":"$" }, "data":[ {"id": "AL", "value": "70" }, { "id": "AK", "value": "100" },
{"id": "AZ", "value": "90" }, { "id": "AR", "value": "72" } ] });
|
setChartDataUrl(URL:String, dataFormat: string) |
Sets or changes the data of the map to a specified URL. The URL has to be relative to the web page where the map is deployed. By default, cross-domain URLs 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". |
myMap.setChartDataUrl("mydynamicdata.aspx", "json");
or
myMap.setChartDataUrl("mydynamicdata.aspx", "xml");
|
setChartData(dataSource: string, dataFormat: string) |
Sets or changes the data of the map.
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 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 JSON String or JSON object
|
myMap.setChartData( "myxmldata.jsp" , "xmlurl");
or
myMap.setChartData( "<map><set value='2310'/></map>" , "xml");
or
myMap.setChartData( "myjsondata.php" , "jsonurl");
or
myMap.setChartData( "{ map : {}, data :[{ value : 100 }] }" , "json");
or
myMap.setChartData( { map : {}, data :[{ value : 100 }] } , "json");
|
setDataURL(URL:string) |
This function helps in setting or updating map XML data for chart from URL. This function takes a URL as string.
setDataURL is deprecated.
|
myMap.setDataURL( "myxmlsource.xml" );
|
setDataXML(dataSource: string) |
This function helps in setting or updating map XML data for a string.
setDataXML is deprecated.
|
myMap.setDataXML( "<map><set value='213' /></map>");
|
SetTransparent ( isTransparent: boolean ) |
Makes the chart background ready to become transparent. You will need to set bgAlpha attribute of the <map> element to finalize the transparency.
The function accepts a Boolean parameter. Only when true is passed, the chart is prepared to have transparent background.
|
myMap.setDataXML( "<map bgAlpha='0' ></map>");
myMap.setTransparent(true);
|
getChartData(dataFormat:string) |
This function returns map 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("myMapId").getChartData( "xml");
var myJSONObj = FusionCharts("myMapId").getChartData( "json" );
|
getXMLData()
or
getXMLData(isUpdatedData:boolean)
|
Returns the XML data of map as string.
|
var myXML = FusionCharts("myMapId").getXMLData(); |
getJSONData() |
Returns the JSON data of map as Object.
|
var myJSONObj = FusionCharts("myMapId").getJSONData();
|
getDataAsCSV() |
Returns the data of map as CSV string. The output CSV string can be configured using XML parameters. String representing data of map in CSV format. |
var strCSV = FusionCharts("myMapId").getDataAsCSV();
|
getXML() |
Returns the XML data of map.
getXML is deprecated.
|
var myXML = FusionCharts("myMapId").getXML();
|
getMapAttribute() |
Returns the value of the attribute as specified in map XML Node or "map" property of JSON data.
Value of the attribute; or "null" if the attribute was empty or not found in XML/SON.
getMapAttribute is deprecated.
|
var color = FusionCharts("myMapId").getMapAttribute( "bgColor");
|
getChartAttribute() |
Returns the value of the attribute as specified in map XML Node or "map" property of JSON data.
Value of the attribute; or "null" if the attribute was empty or not found in XML/SON. |
var color = FusionCharts("myMapId").getChartAttribute( "bgColor");
|
setChartAttribute(name:string, value:string)
or
setChartAttribute(AttributeCollection:Object)
|
Sets map attribute and update the map with the new value. It takes two parameters. The name of the attribute and the value of the parameter.
The name suggests map's root properties (also known as "map attributes" which are passed through the <map> element in map XML data or through map property in map'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 map attributes get changed 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. For example, setChartAttribute( "bgColor" , null ) will remove the palette attribute from the data.
|
myMap.setChartAttribute ( "numberPrefix" , "$" );
or
mapReference.setChartAttribute( { "bgColor" : "ACBF72", bgAlpha : "50"} ); |
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 map properties will be applied to the LinkedCharts. If not provided, the LinkedCharts will inherit properties from the parent map.
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 (map 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 map 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 or 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 or false) Whether the overlay button's text will be bold
- padding: padding around the overlay button in pixels
|
myChart.configureLink(
{
swfUrl: 'Maps/FCMap_World.swf',
width: '30%',
overlayButton:
{
message: ' x ',
bgColor:'999999',
canvasBorderColor: 'cccccc'
}
},
0);
myChart.configureLink(
[ {swfUrl: 'Maps/FCMap_World.swf'},
{swfUrl: 'Maps/Pie2D.swf'},
{swfUrl: 'Maps/Line2D.swf'},
{swfUrl: 'Maps/Area2D.swf'}
]
);
|
resizeTo(width:String, height:String) |
This function resizes an existing map. You can pass the width and height values in percentage or as pixel values (without the px suffix).
Once a map gets resized resized (FC_Resized), drawcomplete events are fired.
|
myMap.resizeTo( "500", "400" )
or
myMap.resizeTo( "80%", "100%" ) |
exportMap( exportSettings: Object) |
Calls the export map routine to save the map 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 map to a server location, a callback function is invoked to convey status of export.
exportMap is deprecated. Use exportChart instead.
|
myMap.exportMap( { exportFormat : 'jpg'} )
|
exportChart( exportSettings: Object) |
Calls the export map routine to save the map 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 map to a server location, a callback function is invoked to convey status of export. |
myMap.exportChart( { exportFormat : 'jpg'} ) |
print() |
Prints a map.
|
FusionCharts("myMapId").print()
|
clone( [chartParams: Object] ) |
The function allows you to duplicate a FusionCharts JavaScript object and uses its settings to create another map.
The function can optionally take an object as parameter. The object can contain map settings which will override the existing settings of the source map before it gets cloned.
The function returns an instance of FusionCharts JavaScript object. |
var newMap = myMap.clone();
or
var newMap = myMap.clone( { swfUrl : 'FCMap_World.swf' } );
|
dispose() |
You can remove a map instance from page and memory using the dispose()function.
Additionally, the function will raise the BeforeDispose event prior to removing a map and disposed after the map has been removed. |
FusionCharts("myMapId").dispose();
|
chartType() |
This function returns the map type or map alias of the rendered map. |
var strCharType = FusionCharts("myMapId").chartType();
|
isActive() |
This function checks whether a Flash map is visible and active. Returns true or false. |
var strCharType = FusionCharts("myMapId").isActive(); |
hasRendered() |
This function returns Boolean value indicating whether the map has finished rendering.
hasRendered() is deprecated
|
var strCharType = FusionCharts("myMapId").hasRendered(); |
signature() |
It returns a string representing the signature of map. For FusionMaps XT maps, it's "FusionMaps/3.2.0 (XT)" |
var strCharType = FusionCharts("myMapId").signature(); |
|
FusionCharts.printManager class - static functions |
configure(configuration: Object)
Note: Print Manager works only in browsers that supports canvas object.
|
This function configures 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 maps until the maps are prepared for printing. The default value is : 'Map 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 maps in a page for managed print. |
FusionCharts.printManager.enabled(true);
|
managedPrint() |
Prints the map once the print manager completes its process of making the map ready for managed print. After the function is called, it waits till the maps become ready. |
FusionCharts.printManager.managedPrint();
|
isReady() |
Returns true when the print manger has completed the process of making all maps 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 an 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 maps offer.
While using a single parameter you need to pass true to enable debugMode.
You can use a compact format which sets output function as well as output format and enables the 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'); |