Pie/Doughnut Chart - JavaScript API |
Pie 3D, Pie 2D, Doughnut 3D and Doughnut 2D charts expose a special function for better interactivity. Shown below is a table which contains detailed description of the functions: |
Usage Example: |
Given below are examples of how to use the function using JavaScript. |
<html> <head> <title>Pie/Doughnut slicing API</title> <script type="text/javascript" SRC="../../../Charts/FusionCharts.js"></script> <script type="text/javascript"> function slicePie() { // get the index of the slice to toggle slice = document.getElementById('index').value ; // toggle the slice FusionCharts("myChartId").togglePieSlice(slice); } </script> </head> <body> <div id="chartContainer">FusionCharts</div> <script language="JavaScript"> var myChart = new FusionCharts("../../../Charts/Pie3D.swf", "myChartId", "400", "300", "0", "1"); myChart.setXMLUrl("Data.xml"); myChart.render("chartContainer"); </script> <input type="text" id="index" size="5" value="0"/> <input type="button" value="Toggle" onClick="slicePie()"/> </body> </html> In the above code, we have created a Pie 3D chart with four slices. We have created a text input button to take pie slice index value as input. When a number is provided in the input box and Toggle button is clicked, togglePieSlice function is called. The slice ID is passed to the function. In effect, the desired slice slices-out or slices-in. See it live! |
enableSlicingMovement() |
<html> <head> <title>Pie/Doughnut Enable Slicing Interactivity - API</title> <script type="text/javascript" SRC="../../../Charts/FusionCharts.js"></script> <script type="text/javascript"> function enableSlicing() { // Enable the slicing interactivity of the chart FusionCharts("myChartId").enableSlicingMovement(); } </script> </head> <body> <div id="chartContainer">FusionCharts XT</div> <script language="JavaScript"> var myChart = new FusionCharts("../../../Charts/Pie3D.swf", "myChartId", "400", "300", "0", "1"); myChart.setXMLData("<chart><set value='25' label='Minor' link='j-sliceClicked-25,Minor' /><set value='50' label='Major' link='j-sliceClicked-50,Major' /></chart>"); myChart.render("chartContainer"); </script> In the above code, we have created a Pie 3D chart with slices having links. When the chart is rendered, it enables links of the slices and disables the slicing interactivity. We have created a button which when clicked, will call enableSlicing function. The function, in turn, will call the enableSlicingMovement API function of the chart. The links of the slices will get disabled and a user can click on a slice to achieve desired slicing movements. See it live! |
enableLink() |
<html> <head> <title>Pie/Doughnut slicing API</title> <script type="text/javascript" SRC="../../../Charts/FusionCharts.js"></script> <script type="text/javascript"> function enableChartLinks() { // enable links of the charts FusionCharts("myChartId").enableLink(); } </script> </head> <body> <div id="chartContainer">FusionCharts XT</div> <script language="JavaScript"> var myChart = new FusionCharts("../../../Charts/Pie3D.swf", "myChartId", "400", "300", "0", "1"); myChart.setXMLData("<chart><set value='25' label='Minor' link='j-sliceClicked-25,Minor' /><set value='50' label='Major' link='j-sliceClicked-50,Major' /></chart>"); myChart.render("chartContainer"); </script> <input type="button" value="Enable Slicing interactivity" onclick="FusionCharts('myChartId').enableSlicingMovement();" /> <input type="button" value="Enable Link interactivity" onclick="enableChartLinks()"/> </body> </html> In the above code, we have created a Pie 3D chart with slices having links. When the chart is rendered, it enables links of the slices and disables the slicing interactivity. We have created two buttons. The first button, when clicked will enable slicing interactivity of the chart and subsequently disable link interactivity of the slices. The other button will call enableChartLinks function. This function calls the enableLink API function of the chart. The links of the slices will get enabled and user can now click on the slices to invoke links. See it live! |