Drag Column Chart - Snapping to nearest divisional interval
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>
<!-- ShowCased DragColumn chart's Snapping to nearest divisional interval. The following sample snaps the data point to its nearest div, if the distance between the div and the data point is 5 pixel or minimum.
Attributes:
# snapToDiv
# snapToDivRelaxation
-->
<div>
<div id="chart-container">FusionCharts will render here</div>
<div id="tableCont">
<table>
<tr>
<td></td>
<th>Poultry</th>
<th>Rice</th>
<th>Peanut Butter</th>
<th>Salmon</th>
<th>Cereal</th>
</tr>
<tr>
<td>Estimated Demand</td>
<td id='est-1'>19000</td>
<td id='est-2'>16500</td>
<td id='est-3'>14300</td>
<td id='est-4'>10000</td>
<td id='est-5'>9800</td>
</tr>
</table>
</div>
</div>
CSS
body {
font-family: "Arial", "Verdana", "sans";
font-size: 80%;
}
body>div {
/*only one in this sample */
width: 600px;
}
table {
margin: 25px auto;
border-collapse: collapse;
border: 1px solid;
border-bottom: 2px solid #6baa01;
}
th {
background-color: #008ee4;
color: #ffffff;
}
th,
td {
border: 1px solid #6baa01;
padding: 10px 5px;
min-width: 70px;
text-align: center;
}
tr:nth-child(1)>td:nth-child(1) {
border-color: #fff;
}
tr:nth-child(2)>td {
color: #6baa01;
}
tr:nth-child(2)>td:nth-child(1) {
background-color: #6baa01;
color: #fff;
}
#tableCont {
width: 100%;
}
JavaScript
FusionCharts.ready(function() {
var inventoryChart = new FusionCharts({
type: 'dragcolumn2d',
renderAt: 'chart-container',
width: '500',
height: '350',
dataFormat: 'json',
dataSource: {
"chart": {
"caption": "Inventory status - Bakersfield Central",
"subCaption": "Top 5 Food items",
"xAxisName": "Food Item",
"yAxisName": "No. of Units",
"snapToDiv": "1",
"snapToDivRelaxation": "5",
"theme": "fusion"
},
"categories": [{
"category": [{
"label": "Poultry"
},
{
"label": "Rice"
},
{
"label": "Peanut Butter"
},
{
"label": "Salmon"
},
{
"label": "Cereal"
}
]
}],
"dataset": [{
"seriesname": "Available Stock",
"allowDrag": "0",
"data": [{
"value": "6000"
},
{
"value": "9500"
},
{
"value": "11900"
},
{
"value": "8000"
},
{
"value": "9700"
}
]
},
{
"seriesname": "Estimated Demand",
"dashed": "1",
"data": [{
"value": "19000"
},
{
"value": "16500"
},
{
"value": "14300"
},
{
"value": "10000"
},
{
"value": "9800"
}
]
}
]
},
events: {
'dataplotDragEnd': function(evt, arg) {
var dtIndx = arg && arg.dataIndex,
val = arg && parseInt(arg.endValue, 10);
document.getElementById('est-' + dtIndx).innerHTML = val;
},
'dataRestored': function(evtObj) {
var estimatedOrigValues = ["19000", "16500",...