Highcharts Motion 3D Bars

author(s): Lars Cabrera

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>
<script src="https://cdn.jsdelivr.net/gh/larsac07/Motion-Highcharts-Plugin/motion.js"></script>
<script src="https://code.jquery.com/jquery-3.1.1.min.js"></script>

<div id="container"></div>
<div id="sliders">
	<div id="slider-alpha" class="slider-container">
		<p>Alpha Angle</p>
		<input id="R0" type="range" min="0" max="45" value="15"/> <span id="R0-value" class="value"></span>
	</div>
	<div id="slider-beta" class="slider-container">
		<p>Beta Angle</p>
		<input id="R1" type="range" min="0" max="45" value="-45"/> <span id="R1-value" class="value"></span>
	</div>
</div>

CSS

@import "http://netdna.bootstrapcdn.com/font-awesome/4.0.3/css/font-awesome.css";
#container {
    height: 300px;
    min-width: 310px;
    max-width: 800px;
    margin: 0 auto;
}
#sliders {
    text-align: center;
    margin-top: 50px;
}
.slider-container {
    display: inline-block;
}
.loading {
    margin-top: 10em;
    text-align: center;
    color: gray;
}
#play-controls {
    text-align: center;
    width: 100%;
    padding: 5px 0 1em 0;
}
#play-controls * {
    display: inline-block;
    vertical-align: middle;
}
#play-pause-button {
    width: 30px;
    height: 30px;
    text-align: center;
    font-size: 15px;
    outline: none;
    cursor: pointer;
}
#play-range {
    margin: 2.5%;
    width: 70%;
}
#play-output {
    font-family:"Lucida Grande", "Lucida Sans Unicode", Arial, Helvetica, sans-serif;
}

JavaScript

var chart = Highcharts.chart('container', {
    chart: {
        type: 'column',
        margin: 75,
        options3d: {
            enabled: true,
            alpha: 15,
            beta: 15,
            depth: 50,
            viewDistance: 25
        }
    },
    title: {
        text: 'Fruit Consumption'
    },
    xAxis: {
        categories: ['Apples', 'Bananas', 'Oranges']
    },
    yAxis: {
        title: {
            text: 'Fruit eaten'
        }
    },
    motion: {
        enabled: true,
        axisLabel: 'year',
        labels: [2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010],
        series: [0, 1], // The series which holds points to update
        autoPlay : true,
        updateInterval: 10,
        magnet: {
            round: 'floor', // ceil / floor / round
            step: 0.02
        }
    },
    plotOptions: {
        column: {
            depth: 25
        }
    },
    series: [{
        name: 'Jane',
        data: [
            {
                sequence: [1, 5, 2, 7, 7, 1, 6, 9, 2, 5, 1]
            }, {
                sequence: [5, 5, 7, 7, 3, 8, 9, 9, 1, 7, 3]
            }, {
                sequence: [7, 1, 9, 3, 7, 4, 3, 8, 7, 1, 4]
            }

        ]
    }, {
        name: 'John',
        data: [
            {
                sequence: [7, 1, 9, 3, 7, 4, 3, 8, 7, 1, 4]
            }, {
                sequence: [1, 5, 2, 7, 7, 1, 6, 9, 2, 5, 1]
            }, {
                sequence: [9, 1, 7, 3, 3, 2, 1, 4, 5, 6, 7]
            }
        ]
    }]
});

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(true);
});
$('#R1').on('change', function () {
    chart.options.chart.options3d.beta = this.value;
    showValues();
    chart.redraw(true);
});

showValues();