You are viewing documentation for an older version. For current documentation - click here.

Starting FusionWidgets XT, you can use the popular jQuery syntax to render and manipulate FusionWidgets XT. This can be done using the FusionCharts jQuery plugin.

FusionWidgets XT uses the FusionCharts jQuery plugin that takes care of all the products of FusionCharts XT Suite, including FusionWidgets XT.

FusionCharts jQuery plugin helps you to render FusionWidgets 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 the existing features of FusionCharts. 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 recommend you to go through the following sections of documentation (if you've 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 the FusionCharts jQuery plugin

Setting up the FusionCharts jQuery plugin is very easy. You need to follow these simple steps:

  1. Copy all the/required chart SWF files (from the Download Pack > Charts folder) to your preferred folder
  2. Copy FusionCharts.js, jquery.min.js, and FusionCharts.jqueryplugin.js from the Download Pack > Charts folder to the preferred folder
  3. To create JavaScript charts, also copy FusionCharts.HC.js and FusionCharts.HC.Widgets.js from the Download Pack > Charts folder to the preferred folder.
  4. Add references to the required JavaScript files in your code as shown below:

    <script type="text/javascript" src="Charts/jquery.min.js"></script>
    <script type="text/javascript" src="Charts/FusionCharts.js"></script>
    <script type="text/javascript" src="Charts/FusionCharts.jqueryplugin.js"></script>

This completes the setup.

Please note that you do not need to explicitly include FusionCharts.HC.js and FusionCharts.HC.Widgets.js in your code. FusionCharts.js will automatically load these files as and when required.

Creating the first chart using the FusionCharts jQuery plugin

Let's now create our first chart using the FusionCharts jQuery plugin.

Let's create the same customer satisfaction Angular gauge which we had created in the Creating your first chart section as shown in the image below:

First Chart - Weekly Sales

The XML data for this was:

<chart lowerLimit='0' upperLimit='100' lowerLimitDisplay='Bad' upperLimitDisplay='Good' numberSuffix='%' showValue='1'>
   <colorRange>
      <color minValue='0' maxValue='75' code='FF654F'/>
      <color minValue='75' maxValue='90' code='F6BD0F'/>
      <color minValue='90' maxValue='100' code='8BBA00'/>
   </colorRange>
   <dials>
      <dial value='92' />
   </dials>
</chart>

We save this data as Data.xml.

The code to use this data and generate an Angular gauge using the FusionCharts jQuery plugin is as follows:

<html>
  <head> 	
    <title>My First chart using FusionWidgets XT</title> 	
    <script type="text/javascript" src="Charts/FusionCharts.js"></script>
    <script type="text/javascript" src="Charts/jquery.min.js"></script>
    <script type="text/javascript" src="Charts/FusionCharts.jqueryplugin.js"></script>
  </head>   
  <body>     
    <div id="chartContainer">Chart will load here!</div>          
    <script type="text/javascript"><!-- 	
       
      $(document).ready(function(){
          $("#chartContainer").insertFusionCharts({
               swfUrl: "Charts/AngularGauge.swf", 
               dataSource: "Data.xml", 
               dataFormat: "xmlurl", 
               width: "400", 
               height: "200", 
               id: "myChartId"
         }); 

       });
      
    // -->     
    </script> 	   
  </body> 
</html>

We save the above code as FirstChart.html. In the above code we have :

  • Selected the HTML element (DIV) with id chartContainer
  • Called insertFusionCharts method (available from the plugin)
  • Passed all required chart configurations like swfUrl, width, height, dataSource, dataFormat, id etc. to the method as JavaScript object

The insertFusionCharts method renders a chart within the selected HTML element. It takes a set of key/value pairs representing chart configurations as parameter. The set is passed as an Object. The properties of the parameter-object are as follows:

Chart configuration or property Description and acceptable value
swfUrl Path (as string) to the chart SWF file. You can get the list of chart SWF file names from Chart List page.
id Sets the DOM id of the chart. The value is provided as string. (optional)
width Width of the chart  (optional - default is 400). The value is provided as number if the width is in pixels or as string if width is to be set in percentage (e.g., "50%")
height Height of the chart (optional - default is 300). The value is provided as number if the height is set in pixels or as string if the height is to be set in percentage (e.g., "50%")
dataSource XML or JSON chart data. It can be a URL for XML or JSON. It can also be a string containing XML or JSON object
dataFormat Defines the format of the dataSource.
  • Set it to xmlurl when data source is a URL to XML data
  • Set it to xml when the data source is an XML String
  • Set it to jsonurl when data source is a URL to JSON data
  • Set it to json when the data source is a JSON String or JSON object
renderer Sets the chart renderer engine. Acceptable values are 'flash' and 'javascript'. The default value is automatically selected depending on the availability and support of Flash player. When set to javascript FusionCharts JavaScript Class renders pure JavaScript charts. (optional)
bgColor This sets the color of the flash player's background on which a chart gets drawn. It is passed as a string containing hex coded color value. 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 is the default value. There are other settings namely, showAll, ExactFit, noBorder. But these are not supported and might result in distorted charts.  (optional)
lang Sets the language for chart messages. It presently supports only English. 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')
debugMode Sets the chart debug window on. Can take "0" or "1". When set to "1", the chart shows a debug window over itself. (optional - default value is "0")

The resultant chart will be rendered as shown in the image below:

First Chart - Weekly Sales

See it live!

What happens if Flash player is not available?

In case Flash Player is not available on certain devices (like iPad/iPhone), FusionCharts JavaScript Class automatically renders the same chart using JavaScript. If you are running the sample from local file system, please note that you need to provide the data using the Data String method, i.e., passing the data (XML/JSON) to the chart as String or JSON Object. Due to security implementation of many browsers which blocks AJAX in local file systems, and since the JavaScript charts use AJAX, the Data URL method (loading data from external XML/JSON file) will not work.

Rendering the chart as JavaScript

You can also render JavaScript chart using the same method. All you need to do is to explicitly set the renderer property to javascript. In case you are running the sample from local file system, you also need to set the chart data as string. The code snippet below contains the modified sample:

$("#chartContainer").insertFusionCharts({
               swfUrl: "Charts/AngularGauge.swf", 
               renderer: "JavaScript",
               width: "400", 
               height: "300", 
               id: "myChartId",

               dataFormat: "xml", 
               dataSource: "<chart lowerLimit='0' upperLimit='100' lowerLimitDisplay='Bad' " +
					" upperLimitDisplay='Good' numberSuffix='%' showValue='1'> " +
   				" <colorRange> " +
     						" <color minValue='0' maxValue='75' code='FF654F'/>" +
						" <color minValue='75' maxValue='90' code='F6BD0F'/> " +
      						" <color minValue='90' maxValue='100' code='8BBA00'/> " +
   				" </colorRange>" +
   				 " <dials> " +
      					"	<dial value='92' /> " +
  				"	</dials> " +
		"	</chart>"
         }); 

The resultant chart would 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 a URL. To provide data as JSON you 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: "Charts/AngularGauge.swf", 
	width: "400", 
	height: "300", 
	id: "myChartId",
	
	dataFormat: "json", 
	dataSource: {
  "chart": {
    "lowerlimit": "0",
    "upperlimit": "100",
    "lowerlimitdisplay": "Bad",
    "upperlimitdisplay": "Good",
    "numbersuffix": "%",
    "showvalue": "1"
  },
  "colorrange": {
    "color": [
      {
        "minvalue": "0",
        "maxvalue": "75",
        "code": "FF654F"
      },
      {
        "minvalue": "75",
        "maxvalue": "90",
        "code": "F6BD0F"
      },
      {
        "minvalue": "90",
        "maxvalue": "100",
        "code": "8BBA00"
      }
    ]
  },
  "dials": {
    "dial": [
      {
        "value": "92"
      }
    ]
  }
}
}); 

See it live!

The code snippet below shows how you can pass JSON string as data source:

$("#chartContainer").insertFusionCharts({
	swfUrl: "Charts/AngularGauge.swf", 
	width: "400", 
	height: "300", 
	id: "myChartId",
	
	dataFormat: "json", 
	dataSource: '{ ' +
  ' "chart": { ' +
   ' "lowerlimit": "0", ' +
   ' "upperlimit": "100", ' +
   ' "lowerlimitdisplay": "Bad", ' +
   ' "upperlimitdisplay": "Good", ' +
   ' "numbersuffix": "%", ' +
   ' "showvalue": "1" ' +
 ' }, ' +
 ' "colorrange": { ' +
 '   "color": [ ' +
 '     { ' +
       ' "minvalue": "0", ' +
       ' "maxvalue": "75", ' +
       ' "code": "FF654F" ' +
     ' }, ' +
     ' { ' +
      '  "minvalue": "75", ' +
      '  "maxvalue": "90", ' +
      '  "code": "F6BD0F" ' +
     ' }, ' +
     ' { ' +
     '   "minvalue": "90", ' +
      '  "maxvalue": "100", ' +
      '  "code": "8BBA00" ' +
     ' } ' +
   ' ] ' +
 ' }, ' +
 ' "dials": { ' +
   ' "dial": [ ' +
    '  { ' +
     '   "value": "92" ' +
     ' } ' +
   ' ] ' +
 ' } ' +
'}'
}); 

See it live!

The code snippet below shows how you can pass a URL as JSON data source:

$("#chartContainer").insertFusionCharts({
	swfUrl: "Charts/AngularGauge.swf", 
	width: "400", 
	height: "300", 
	id: "myChartId",
	
	dataFormat: "jsonurl", 
	dataSource: "data.json"
}); 

See it live!

Many web servers like IIS6, do not serve .json (no wildcard MIME type) files by default. You need to setup your web server to serve json files. In IIS6 you can do this using these steps:
  • Open the properties for the server in IIS Manager and click MIME Types
  • Click New. Enter "JSON" for the extension and "application/json" for the MIME type

NOTE: Many browsers restrict JavaScript from accessing local file system owing to security reasons. The JavaScript charts, when running locally, will not be able to access JSON data provided as a URL. If you run the files from a server, it will run absolutely fine, though. When running locally, however, if you provide the data as JavaScript Object or JSON String, it works fine.

API Overview

Here is a quick reference map of FusionCharts jQuery API. Click on the desired item to know more.

Name What it does?
insertFusionCharts() method Renders charts inside containers
appendFusionCharts() method Adds chart at the end of containers
prependFusionCharts() method Adds charts at the beginning of containers
cloneFusionCharts() method Clones charts
updateFusionCharts() method Updates chart settings like type, width, height, data, renderer etc.
attrFusionCharts() method Gets a chart attribute or sets one of multiple chart attributes
 
:FusionCharts selector Finds all FusionCharts within a page or an element
 
bind() method Binds an event listener with FusionCharts specific events

In the following pages we will learn how to use FusionCharts jQuery plugin to: