shamasis

General Information

Recommended Posts

FusionCharts DOM

-- A new way to include FusionCharts in your HTML.

Till now, to include a chart/map created by FusionCharts in your HTML page, you had three options:

Direct HTML method:

Directly use the OBJECT/EMBED tag to include the SWF file in your HTML content and then use Flashvars to provide the XML data string or URL. Example.

While this method offers the advantage of just having to use HTML code, the code gets confusing at times and in Microsoft Internet Explorer, you would need to click the chart object to activate it, before you could interact with it.

FusionCharts JavaScript Method:

Use the FusionCharts JavaScript class (FusionCharts.js) that we provide as part of download. Example.

This class provides a better way to include of FusionCharts in your web page, overcame the Internet Explorer "Click to activate" issue, handled a lot of cross-browser issues and also provided additional API to interact with the charts. This has been the recommended method of embedding FusionCharts. The downside of this method was that developers needed to have naive knowledge of JavaScript syntax to use it, though we have provided a lot of examples that can just be replicated.

Using Server-Side API:

Use the language specific API that we've provided for ASP, PHP, ASP.NET, ColdFusion, JSP, Ruby On Rails etc. in the download pack itself. This API allows you to write the code in your programming language to embed the chart. Behind the scenes, the API generates HTML or JavaScript code as explained above in points 1 & 2.

In an effort to make this entire process even better and easier, we released FusionCharts DOM.

[h3]What is FusionCharts DOM?[/h3]Essentially, FusionCharts DOM is a JavaScript file (FusionChartsDOM.js) that you need to include in your HTML page, along with the standard FusionCharts JavaScript class (FusionCharts.js). You can download both the files fromhttp://www.fusioncharts.com/DOM/downloads.asp.

[h3]How to use it?[/h3]Once you've downloaded and included the two JavaScript files in your page, to create a chart, all you need to do is use the <fusioncharts></fusioncharts> tag in your HTML code.

Consider the code below:

<html>
<!-- #comment: your HTML Code here ... -->
<fusioncharts chartType="MSCombi2D" dataUrl="profit_revenue.xml" width="100%"></fusioncharts>
 
<!-- #comment: your HTML Code here... -->
</html>

This code creates a Multi-series combination 2D chart with its data source specified as Profit_revenue.xml. See it live.

There are a lot of attributes which you can specify for <fusioncharts> element. The entire list can be found here.

In-lining your XML data in the HTML code: If you do not wish to have an external XML file and have the XML data in-lined in the HTML code itself, the following code could be used:

<fusioncharts chartType="Doughnut2D" width="100%">
  <data><!--[CDATA[
   <chart caption="Usage share of Web Browsers"
  subcaption="Third quarter of 2008" numberSuffix="%"
  palette='3' pieRadius='90' >
 
  <set name="IE6" tooltext="Internet Explorer 6" value="33.13" />
  <set name="IE7" tooltext="Internet Explorer 7" value="39.09" />
  <set name="Chrome" tooltext="Chrome" value="0.26" />
  <set name="FF" tooltext="Mozilla Firefox" value="19.48" />
  <set name="N" tooltext="Netscape" value="0.68" />
  <set name="Opera" tooltext="Opera" value=".71" />
  <set name="Safari" tooltext="Safari" value="6.39" />
  <set name="Others" tooltext="Others" value="0.26" />
   </chart>
  ]]--></data>
</fusioncharts>

Here, the entire XML data has been inlined under <data> tag. See this live in action.

Added Advantage: Specifying common settings for all charts in page.

If you've multiple charts in a page and wish to specify common settings for all of them,

like width/height, debugMode etc., FusionCharts DOM allows you to specify the same

within the <script> tag as under:

<!-- #comment: script in <head> tag -->
<script type="text/javascript" src="../docs/JavaScripts/FusionChartsDOM.js"
    parameters="chartType: 'Line', width: '200', height: '200'"></script>
	    
<!-- fusioncharts HTML tags in <body> -->
<fusioncharts dataUrl="data/CISCO.xml"></fusioncharts>
<fusioncharts dataUrl="data/IBM.xml"></fusioncharts>
<fusioncharts dataUrl="data/JAVA.xml"></fusioncharts>
<fusioncharts dataUrl="data/INTL.xml"></fusioncharts>

In the above code, the four charts are generated as line chart with a width and height

 of 200 pixels. See it live here.

Support for FusionCharts events: FusionCharts DOM supports all the other events and parameters that are supported by FusionCharts.

If you've already integrated FusionCharts in your applications and wish to switch to DOM,

the transition is seamless and does not break your existing JavaScript too.

You can just replace the existing chart inclusion code with the new DOM style code.

Related links:

FusionCharts DOM may be downloaded here . Or, you may read the online documentation here.

Blog Post: http://blog.fusioncharts.com/2008/11/fusioncharts-dom---a-new-way-to-include-fusioncharts-in-your-html.html

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now