FusionCharts jQuery plugin overview | ||||||||||||||||||||||||||||||||||||||||||||||
Starting FusionMaps XT, you can use popular jQuery syntax to render and manipulate FusionMaps XT. This can be done using FusionCharts jQuery plugin. FusionMaps XT uses the FusionCharts jQuery plugin that takes care of all the products of FusionCharts Suite XT, including FusionMaps XT. FusionCharts jQuery plugin helps you to render FusionMaps XT anywhere within a Web page. Also it helps you to change the map type, update and retrieve map data, update functional and cosmetic settings and use all existing features of FusionCharts. Adding a map at the end or beginning of an existing container is easily possible using this plugin. Moreover, a custom selector helps you find all the maps in your page or in any container element. To aid your understanding of this section, we will recommend you to go through the following sections of documentation (if you have not already read them):
In the following sections of this page, we will see how to set-up and use this plugin. |
||||||||||||||||||||||||||||||||||||||||||||||
Setting up FusionCharts jQuery plugin | ||||||||||||||||||||||||||||||||||||||||||||||
Setting up of FusionCharts jQuery plugin is very easy. You will need to follow these simple steps:
This completes the setup. Please note that you do not need to explicitly include FusionCharts.HC.js and FusionCharts.HC.Maps.js in your code. FusionCharts.js will automatically load these files as and when required. | ||||||||||||||||||||||||||||||||||||||||||||||
Creating the first map using FusionCharts jQuery plugin | ||||||||||||||||||||||||||||||||||||||||||||||
Let us now create our first map using FusionCharts jQuery plugin. We will start with the same population data which we have created in Creating your first map page as shown below:
We had already saved this data as Data.xml. The code to use this data and generate a world map using FusionCharts jQuery plugin is as follows: <html> <head> <title>My First map using FusionMaps</title> <script type="text/javascript" src="Maps/jquery.min.js"></script> <script type="text/javascript" src="Maps/FusionCharts.js"></script> <script type="text/javascript" src="Maps/FusionCharts.jqueryplugin.js"></script> </head> <body> <div id="mapContainer">FusionMaps XT will load here!</div> <script type="text/javascript"><!-- $(document).ready(function(){ $("#mapContainer").insertFusionCharts({ swfUrl: "Maps/FCMap_World.swf", dataSource: "Data.xml", dataFormat: "xmlurl", width: "400", height: "300", id: "myMapId" }); }); // --> </script> </body> </html> We save the above code as FirstMap.html. In the above code we have:
The insertFusionCharts method renders a map within the selected element. It takes a set of key or value pairs representing map configurations as parameter. The set is passed as an Object. The properties of the parameter-object are as follows:
The resultant map will be rendered as shown in the image below:
What happens if Flash player is not available? |
||||||||||||||||||||||||||||||||||||||||||||||
Rendering the map as JavaScript | ||||||||||||||||||||||||||||||||||||||||||||||
You can also render JavaScript map using the same method. All you will need to do is to explicitly set the renderer property to javascript. In case you are running the sample from local file system, you will also need to set the map data as string. The code snippet below contains the modified sample: $("#mapContainer").insertFusionCharts({ swfUrl: "Maps/FCMap_World.swf", renderer: "JavaScript", width: "400", height: "300", id: "myMapId", dataFormat: "xml", dataSource: "<map borderColor='005879' fillColor='D7F4FF' numberSuffix='M' includeValueInLabels='1' labelSepChar=':' baseFontSize='9'>" + "<data>" + "<entity id='NA' value='515' />" + "<entity id='SA' value='373'/>" + "<entity id='AS' value='3875' />" + "<entity id='EU' value='727' />" + "<entity id='AF' value='885' />" + "<entity id='AU' value='32' />" + "</data>" + "</map>" }); The resultant map will look like the image shown below: |
||||||||||||||||||||||||||||||||||||||||||||||
Using JSON as data source | ||||||||||||||||||||||||||||||||||||||||||||||
Apart from XML you can also provide data in JSON format. You can provide JSON as JavaScript Object, as JSON string or as a URL. To provide data as JSON you will need to pass the JSON data source to dataSource property and set json or jsonurl to dataFormat property. The code snippet below shows how you can pass JSON Object as data source: $("#mapContainer").insertFusionCharts({ swfUrl: "Maps/FCMap_World.swf", width: "400", height: "300", id: "myMapId", dataFormat: "json", dataSource:{ "map": { "bordercolor": "005879", "fillcolor": "D7F4FF", "numbersuffix": "M", "includevalueinlabels": "1", "labelsepchar": ":", "basefontsize": "9" }, "data": [ { "id": "NA", "value": "515" }, { "id": "SA", "value": "373" }, { "id": "AS", "value": "3875" }, { "id": "EU", "value": "727" }, { "id": "AF","value": "885" }, { "id": "AU", "value": "32" } ] }); The code snippet below shows how you can pass JSON string as data source: $("#mapContainer").insertFusionCharts({ swfUrl: "Maps/FCMap_World.swf", width: "400", height: "300", id: "myMapId", dataFormat: "json", dataSource: '{ ' + ' "map": { ' + ' "bordercolor": "005879", ' + ' "fillcolor": "D7F4FF", ' + ' "numbersuffix": "M", ' + ' "includevalueinlabels": "1", ' + ' "labelsepchar": ":", ' + ' "basefontsize": "9" ' + ' }, ' + ' "data": [ ' + ' { "id": "NA", "value": "515" }, ' + ' { "id": "SA", "value": "373" }, ' + ' { "id": "AS", "value": "3875" }, ' + ' { "id": "EU", "value": "727" }, ' + ' { "id": "AF","value": "885" }, ' + ' { "id": "AU", "value": "32" } ' + ' ] ' + ' } ' + ' } ' ); The code snippet below shows how you can pass a URL containing JSON as data source: $("#mapContainer").insertFusionCharts({ swfUrl: "Maps/FCMap_World.swf", width: "400", height: "300", id: "myMapId", dataFormat: "jsonurl", dataSource: "data.json" }); |
||||||||||||||||||||||||||||||||||||||||||||||
API Overview | ||||||||||||||||||||||||||||||||||||||||||||||
Here is a quick reference map of FusionCharts jQuery API. Click on the desired item to know more.
|
||||||||||||||||||||||||||||||||||||||||||||||
In the following pages we will learn how to use FusionCharts jQuery plugin to: |
||||||||||||||||||||||||||||||||||||||||||||||