JSFiddle - React, Tailwind, and code Playground
by tankchintan
HTML
<script src="http://code.highcharts.com/stock/highstock.js"></script>
<script src="http://code.highcharts.com/stock/modules/exporting.js"></script>
<script type="text/JavaScript">
var store = {};
</script>
<script src="https://s3.amazonaws.com/webapps-archive/stats/main-total-ts-2003-2013.js"></script>
<script src="https://s3.amazonaws.com/webapps-archive/stats/twitter-total-ts-2003-2013.js"></script>
<div id="container" style="height: 500px; min-width: 600px"></div>
JavaScript
$(function() {
console.log(store)
var seriesOptions = [],
yAxisOptions = [],
seriesCounter = 0,
names = ['Main', 'Twitter'];
$.each(names, function(i, name) {
var data = store[name];
seriesOptions[i] = {
name: name,
data: data
};
// As we're loading the data asynchronously, we don't know what order it will arrive. So
// we keep a counter and create the chart when all the data is loaded.
seriesCounter++;
if (seriesCounter == names.length) {
createChart();
}
});
// create the chart when all data is loaded
function createChart() {
$('#container').highcharts('StockChart', {
chart: {
},
rangeSelector: {
selected: 4
},
yAxis: {
labels: {
formatter: function() {
return (this.value > 0 ? '+' : '') + this.value + '%';
}
},
plotLines: [{
value: 0,
width: 2,
color: 'silver'
}]
},
legend: {
enabled: true,
layout: 'vertical',
verticalAlign: 'top',
y: 100,
shadow: true
},
plotOptions: {
series: {
compare: 'percent'
}
},
tooltip: {
pointFormat: '<span style="color:{series.color}">{series.name}</span>: <b>{point.y}</b> ({point.change}%)<br/>',
valueDecimals: 0
},
series: seriesOptions
});
}
});