Draggable Rotating Highchart
by wrxsti85
HTML
<script src="http://code.highcharts.com/highcharts.js"></script>
<script src="http://code.highcharts.com/highcharts-3d.js"></script>
<script src="http://code.highcharts.com/modules/exporting.js"></script>
<div id="container"></div>
<div id="sliders">
<table>
<tr>
<td>Alpha Angle</td>
<td>
<input id="R0" type="range" min="0" max="45" value="15" /> <span id="R0-value" class="value"></span>
</td>
</tr>
<tr>
<td>Beta Angle</td>
<td>
<input id="R1" type="range" min="0" max="45" value="15" /> <span id="R1-value" class="value"></span>
</td>
</tr>
</table>
</div>
JavaScript
$(function(){
// Set up the chart
var chart = new Highcharts.Chart({
chart: {
renderTo: 'container',
type: 'column',
margin: 75,
options3d: {
enabled: true,
alpha: 15,
beta: 15,
depth: 25,
viewDistance: 100
}
},
title: {
text: 'Chart rotation demo'
},
subtitle: {
text: 'Test by dragging the chart'
},
plotOptions: {
column: {
depth: 25
}
},
series: [{
data: [29.9, 71.5, 106.4, 129.2, 144.0, 176.0, 135.6, 148.5, 216.4, 194.1, 95.6, 54.4]
}]
});
function showValues() {
$('#R0-value').html(chart.options.chart.options3d.alpha);
$('#R1-value').html(chart.options.chart.options3d.beta);
}
// Activate the sliders
$('#R0').on('change', function () {
chart.options.chart.options3d.alpha = this.value;
showValues();
chart.redraw(false);
});
$('#R1').on('change', function () {
chart.options.chart.options3d.beta = this.value;
showValues();
chart.redraw(false);
});
showValues();
var nx,
ny,
lx,
ly,
mouseState,
alpha = 0,
beta = 0;
$('#container').mousedown(function(){
mouseState = true;
}).mouseup(function(){
mouseState = false;
});
$('#container').mousemove(function(event) {
if(mouseState){
lx = nx;
ly = ny;
nx = event.pageX;
ny = event.pageY;
if(lx < nx){
beta--;
beta--;
} else {
beta++;
beta++;
}
if(ly < ny){
alpha++;
alpha++;
} else {
alpha--;
...