FusionCharts API-Methods: slicePlotItem
Created using FusionCharts Suite XT - www.fusioncharts.com
by FusionCharts
HTML
<script src="https://static.fusioncharts.com/code/latest/fusioncharts.js"></script>
<script src="https://static.fusioncharts.com/code/latest/fusioncharts.charts.js"></script>
<script src="https://static.fusioncharts.com/code/latest/themes/fusioncharts.theme.fint.js"></script>
<!-- This sample shows the usage of the slicePlotItem() method. -->
<div id="indicatorDiv">Method Name: <strong>slicePlotItem()</strong>
<p>Slices in/slices out a pie/doughnut slice.</p>
<p>When a pie-slice is selected from the drop-down given below, the corresponding slice on the pie chart is sliced out. Because multi-slicing has been disabled in the JSON chart data, when one slice is sliced out, the previously sliced out slice is sliced in.</p>
<div class="text-center">
<select id="slice_name" class="mb-20">
<option value="0">Teenager</option>
<option value="1">Adult</option>
<option value="2">Mid-age</option>
</select>
<div id="chart-container">FusionCharts will render here</div>
</div>
</div>
CSS
body {
padding: 5px;
margin: 0 auto;
}
strong{
font-weight: bold;
}
.text-center {
text-align: center;
}
p {
margin: 10px auto;
}
.mb-20 {
margin-bottom: 20px;
}
#indicatorDiv {
width: 500px;
font-family:'Arial', 'Helvetica';
font-size: 13px;
}
#slice_name {
height: 25px;
font-size: 12px;
}
JavaScript
FusionCharts.ready(function () {
var ageGroupChart = new FusionCharts({
type: 'pie2d',
renderAt: 'chart-container',
width: '350',
height: '350',
dataFormat: 'json',
dataSource: {
"chart": {
"caption": "Split of Visitors by Age Group",
"subCaption": "Last year",
"captionFontSize": "13",
"subcaptionFontSize": "12",
"theme": "fint",
"enableMultiSlicing": "0"
},
"data": [{
"label": "Teenage",
"value": "1250400",
"isSliced": "1"
}, {
"label": "Adult",
"value": "1463300"
}, {
"label": "Mid-age",
"value": "1050700"
}]
}
}).render();
var msg = document.getElementById("msg");
/**
* @description
* The slicePlotItem() method slices in/slices out a pie/doughnut slice.
*
* @param {Number} index: Index of the pie/doughnut slice
* @param {Boolean} slice: If set to true, it will slice out a slice, which is in the sliced-in state. If the slice is already in the sliced-out state, the state is retained.
*
* usage: chartObj.slicePlotItem(index,slice);
*
*/
function slice() {
var slice_name = document.getElementById("slice_name");
var flag = ageGroupChart.slicePlotItem(slice_name.value, true);
}
document.getElementById("slice_name").addEventListener("change", slice);
});