FusionCharts --Auto adjust tick marks in Cylinder gauge
Created using FusionCharts Suite XT - www.fusioncharts.com
by FusionCharts
HTML
<script src="https://cdn.fusioncharts.com/fusioncharts/latest/fusioncharts.js"></script>
<script src="https://cdn.fusioncharts.com/fusioncharts/latest/themes/fusioncharts.theme.fusion.js"></script>
<!-- Automatically adjusting tick marks in a Cylinder gauge showing the consumption of Diesel in Generator in Bakersfield Central outlet using attributes:
# adjustTM - Automatically adjust the number of major ticks and their values to a best feasible value if set to 1
Note : Attribute majorTMNumber intensionally set to 8 so as to show how adjustTM automatically adjust it to 9.
-->
<div id="chart-container">FusionCharts will render here</div>
<div id="checkbox-container">
<input type="checkbox" id="tMarkCB">Adjust Tickmark ?</input>
</div>
JavaScript
FusionCharts.ready(function() {
var adjustTickCB = document.getElementById('tMarkCB'),
fuelWidget = new FusionCharts({
type: 'cylinder',
dataFormat: 'json',
id: 'fuelMeter',
renderAt: 'chart-container',
width: '200',
height: '350',
dataSource: {
"chart": {
"theme": "fusion",
"caption": "Diesel Level in Generator",
"subcaption": "Bakersfield Central",
"lowerLimit": "0",
"upperLimit": "120",
"lowerLimitDisplay": "Empty",
"upperLimitDisplay": "Full",
"numberSuffix": " ltrs",
"showValue": "1",
"chartBottomMargin": "25",
"majorTMNumber": "8",
"minorTMNumber": "2",
//To adjust the tickmark and values automatically
//to a best feasible value
"adjustTM": "0"
},
"value": "75"
}
}).render();
//Set event listener for check boxes
adjustTickCB.addEventListener && adjustTickCB.addEventListener("click", adjustTicks);
//Function to show/hide labels
function adjustTicks(evt, obj) {
//Using adjustTM attribute to adjust the
//number of major ticks to a best feasible value
if (adjustTickCB.checked) {
fuelMeter.setChartAttribute('adjustTM', 1);
} else {
fuelMeter.setChartAttribute('adjustTM', 0);
}
}
});