FusionCharts jQuery plugin overview | ||||||||||||||||||||||||||||||||||||||||
Starting FusionCharts XT, you can use popular jQuery syntax to render and manipulate FusionCharts. This can be done using FusionCharts jQuery plugin. FusionCharts jQuery plugin helps you to render FusionCharts XT anywhere within a web page. Also it helps you to change chart type, update and retrieve chart data, update functional and cosmetic settings and use all existing features of FusionCharts XT. Adding a chart at the end or beginning of an existing container is easily possible using this plugin. Moreover, a custom selector helps you find all the charts 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. Code examples and data files discussed in this section are present in Download Package > Code > jQuery folder |
||||||||||||||||||||||||||||||||||||||||
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.Charts.js in your code. FusionCharts.js will automatically load these files as and when required. Creating the first chart using FusionCharts jQuery plugin Let us now create our first chart using FusionCharts jQuery plugin. We will start with the same Weekly Sales data which we have created in Creating your first chart page as shown below:
We had already saved this data as Data.xml. The code to use this data and generate a Column 3D chart using FusionCharts jQuery plugin is as follows: <html> <head> <title>My First chart using FusionCharts XT</title> <script type="text/javascript" src="FusionCharts/FusionCharts.js"></script> <script type="text/javascript" src="FusionCharts/jquery.min.js"></script> <script type="text/javascript" src="FusionCharts/FusionCharts.jqueryplugin.js"></script> </head> <body> <div id="chartContainer">FusionCharts XT will load here!</div> <script type="text/javascript"><!-- $(document).ready(function(){ $("#chartContainer").insertFusionCharts({ swfUrl: "FusionCharts/Column3D.swf", dataSource: "Data.xml", dataFormat: "xmlurl", width: "400", height: "300", id: "myChartId" }); }); // --> </script> </body> </html> We save the above code as FirstChart.html. In the above code we have :
The insertFusionCharts method renders a chart within the selected element. It takes a set of key or value pairs representing chart configurations as parameter. The set is passed as an Object. The properties of the parameter-object are as follows:
The resultant chart will be rendered as shown in the image below: See it live! |
||||||||||||||||||||||||||||||||||||||||
What happens if Flash player is not available? |
||||||||||||||||||||||||||||||||||||||||
Rendering the chart as JavaScript | ||||||||||||||||||||||||||||||||||||||||
You can also render JavaScript chart 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 chart data as string. The code snippet below contains the modified sample: | ||||||||||||||||||||||||||||||||||||||||
$("#chartContainer").insertFusionCharts({ swfUrl: "FusionCharts/Column3D.swf", renderer: "JavaScript", width: "400", height: "300", id: "myChartId", dataFormat: "xml", dataSource: "<chart caption='Weekly Sales Summary' xAxisName='Week' " + "yAxisName='Sales' numberPrefix='$'>" + "<set label='Week 1' value='14400' />" + "<set label='Week 2' value='19600' />" + "<set label='Week 3' value='24000' />" + "<set label='Week 4' value='15700' />" + "</chart>" }); The resultant chart will look like the image shown below: See it live! |
||||||||||||||||||||||||||||||||||||||||
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 an 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: $("#chartContainer").insertFusionCharts({ swfUrl: "FusionCharts/Column3D.swf", width: "400", height: "300", id: "myChartId", dataFormat: "json", dataSource: { "chart": { "caption" : "Weekly Sales Summary" , "xAxisName" : "Week", "yAxisName" : "Sales", "numberPrefix" : "$" }, "data" : [ { "label" : "Week 1", "value" : "14400" }, { "label" : "Week 2", "value" : "19600" }, { "label" : "Week 3", "value" : "24000" }, { "label" : "Week 4", "value" : "15700" } ] } }); See it live! The code snippet below shows how you can pass JSON string as data source: $("#chartContainer").insertFusionCharts({ swfUrl: "FusionCharts/Column3D.swf", width: "400", height: "300", id: "myChartId", dataFormat: "json", dataSource: '{ "chart": { "caption" : "Weekly Sales Summary" , "xAxisName" : "Week", "yAxisName" : "Sales", "numberPrefix" : "$" }, ' + ' "data" : [ ' + ' { "label" : "Week 1", "value" : "14400" }, ' + ' { "label" : "Week 2", "value" : "19600" }, ' + ' { "label" : "Week 3", "value" : "24000" }, ' + ' { "label" : "Week 4", "value" : "15700" } ' + ' ] }' }); See it live! The code snippet below shows how you can pass an URL containing JSON as data source: $("#chartContainer").insertFusionCharts({ swfUrl: "FusionCharts/Column3D.swf", width: "400", height: "300", id: "myChartId", dataFormat: "jsonurl", dataSource: "data.json" }); See it live! |
||||||||||||||||||||||||||||||||||||||||
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: |
||||||||||||||||||||||||||||||||||||||||