Create New Item
Item Type
File
Folder
Item Name
Search file in folder and subfolders...
Are you sure want to rename?
File Manager
/
dump
/
DrillDown
:
JavaScript.html
Advanced Search
Upload
New Item
Settings
Back
Back Up
Advanced Editor
Save
<?xml version="1.0" encoding="iso-8859-1"?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>FusionCharts Free Documentation</title> <link rel="stylesheet" href="../Style.css" type="text/css" /> <style type="text/css"> <!-- .style4 {color: #E0E0E0} --> </style> </head> <body> <table width="98%" border="0" cellspacing="0" cellpadding="3" align="center"> <tr> <td><h2 class="pageHeader">Using JavaScript functions as links</h2></td> </tr> <tr> <td valign="top" class="text"><p>Instead of using simple links, you can also set JavaScript links using FusionCharts i.e., you can invoke a JavaScript function present in the same page (in which the chart is present) when the end viewer clicks a data element on the chart. To attain this, all you need to do is place the name of JavaScript function instead of the link URL, as under:</p> <p class="codeInline"><span class="codeBlock"><set name='Japan' value='123' <strong>link="JavaScript:myJS('Japan, 123');"</strong> color='F6BD0F'/> </span></p> <p>In the above code, <span class="codeInline">myJS</span> refers to a custom JavaScript function present in the HTML page that embeds this chart. You can also specify any number of parameters for this function. When you now click the data item (column, pie, bar etc.) for this particular data, <span class="codeInline">myJS </span>function would be invoked and 'Japan, 123' would be passed to the function as the function parameter. Here, we've passed the data label and value just for demonstration purposes. In actual charts, you can pass identifier numbers or strings to each data. When the user clicks on the link, these identifiers can be sent back to your JavaScript functions for further actions (like loading detailed data for that identifier using AJAX or anything - the possibilities are endless).</p> <p>Let's quickly put up an example for this kind of links. We'll create a simple 2D Column chart indicating "ABC Bank Branches" in Asia. Each column when clicked, would pass its label and value to our custom JavaScript function <span class="codeInline">myJS</span>, which (for the sake of demonstration) would just write it out in an alert box. </p> <p>We create <span class="codeInline">JSExample.html</span> for this example in <span class="codeInline">DrillDown</span> folder. It contains the following HTML code:</p></td> </tr> <tr> <td valign="top" class="codeBlock"><html><br /> <head><br /> <title>JavaScript Link Example</title><br /> <script language="JavaScript" src="../FusionCharts/FusionCharts.js"></script><br /> <strong> <SCRIPT LANGUAGE="JavaScript"><br /> <!--<br /> function myJS(myVar){<br /> window.alert(myVar);<br /> }<br /> //--><br /> </SCRIPT><br /> </strong> </head> <p><body bgcolor="#ffffff"><br /> <div id="chartdiv" align="center">The chart will appear within this DIV. This text will be replaced by the chart.</div><br /> <script type="text/javascript"><br /> var myChart = new FusionCharts("../FusionCharts/FCF_Column2D.swf", "myChartId", "500", "300");<br /> myChart.setDataURL("JSExample.xml");<br /> myChart.render("chartdiv");<br /> </script><br /> </body><br /> </html><br /> </p></td> </tr> <tr> <td valign="top" class="text"><p>Here, we've a defined a function <span class="codeInline">myJS</span> which will respond to the clicks generated from the chart.</p> <p>And now<span class="codeInline"> JSExample.xml</span> looks as under:</p></td> </tr> <tr> <td valign="top" class="codeBlock"><graph caption='ABC Bank Branches' subCaption='(In Asian Countries)' yaxislabel='Branches' xaxislabel='Country' decimalPrecision='0' bgcolor='F3f3f3' ><br /> <set name='Hong Kong' value='235' <strong>link="JavaScript:myJS('Hong Kong, 235');"</strong> color='AFD8F8'/> <br /> <set name='Japan' value='123' <strong>link="JavaScript:myJS('Japan, 123');"</strong> color='F6BD0F'/> <br /> <set name='Singapore' value='129' <strong>link="JavaScript:myJS('Singapore, 129');" </strong>color='8BBA00'/> <br /> <set name='Malaysia' value='121' <strong>link="JavaScript:myJS('Malaysia, 121');" </strong>color='FF8E46'/> <br /> <set name='Taiwan' value='110' <strong>link="JavaScript:myJS('Taiwan, 110');" </strong>color='008E8E'/> <br /> <set name='China' value='90' <strong>link="JavaScript:myJS('China, 90');"</strong> color='D64646' /> <br /> <set name='S. Korea' value='86' <strong>link="JavaScript:myJS('S. Korea, 86');" </strong>color='8E468E'/> <br /> </graph></td> </tr> <tr> <td valign="top" class="text">As you can see above, for each data item, we've defined a JavaScript link, that points to the custom function <span class="codeInline">myJS</span>. To this function, we're passing the name and value of the data item. <p>When you view the chart and click on a column, you'll see something like under:</p></td> </tr> <tr> <td valign="top" class="text"><img src="Images/JavaScript.jpg" /></td> </tr> </table> </body> </html>