Created
September 4, 2016 08:54
-
-
Save tnrn9b/954519a24108c19d235c8ae9a5a8bcb5 to your computer and use it in GitHub Desktop.
With Highstock JS v2.0.4 (2014-09-02)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var historyCharts; | |
$(document).ready(function() { | |
var url; | |
url = $('#history-path').val(); | |
if (url.length > 0) { | |
$.ajax({ | |
url: url, | |
context: document.body | |
}).done(function(data) { | |
historyCharts = data; | |
initCharts(); | |
}); | |
} | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// Default High Chart (Showing just values) | |
// | |
var initCharts = function() { | |
var y_axis_max = Math.max(Math.max.apply(Math, historyCharts.total_likes_series), | |
Math.max.apply(Math, historyCharts.total_comments_series), | |
Math.max.apply(Math, historyCharts.total_shares_series)); | |
var x_axis_max = (historyCharts.time_series.length >= 20 ? 20 : historyCharts.time_series.length); | |
$('#chart-container').highcharts({ | |
chart: { | |
type: 'column', | |
zoomType: 'x' | |
}, | |
title: { | |
text: 'Likes, Shares, Comments' | |
}, | |
xAxis: { | |
categories: historyCharts.time_series, | |
min: 0, | |
max: x_axis_max | |
}, | |
yAxis: { | |
min: 0, | |
max: y_axis_max, | |
title: { | |
text: 'Total Likes, Shares, Comments' | |
} | |
}, | |
credits: { | |
enabled: true, | |
position: { | |
align: 'right', | |
x: -10, | |
verticalAlign: 'bottom', | |
y: -5 | |
}, | |
href: "example", | |
text: "example" | |
}, | |
scrollbar: { | |
enabled: true | |
}, | |
legend: { | |
align: 'right', | |
x: -70, | |
verticalAlign: 'top', | |
y: 20, | |
floating: true, | |
backgroundColor: ((Highcharts.theme && Highcharts.theme.legendBackgroundColorSolid) || 'white'), | |
borderColor: '#CCC', | |
borderWidth: 1, | |
shadow: false | |
}, | |
series: [{ | |
name: 'Total Likes', | |
data: historyCharts.total_likes_series | |
}, { | |
name: 'Total Comments', | |
data: historyCharts.total_comments_series | |
}, { | |
name: 'Total Shares', | |
data: historyCharts.total_shares_series | |
}], | |
scrollbar: { | |
enabled: true, | |
barBackgroundColor: 'gray', | |
barBorderRadius: 7, | |
barBorderWidth: 0, | |
buttonBackgroundColor: 'gray', | |
buttonBorderWidth: 0, | |
buttonArrowColor: 'yellow', | |
buttonBorderRadius: 7, | |
rifleColor: 'yellow', | |
trackBackgroundColor: 'white', | |
trackBorderWidth: 1, | |
trackBorderColor: 'silver', | |
trackBorderRadius: 7 | |
}, | |
}); | |
$("#deltaChartRadio").on('change', function() { | |
if($(this).is(':checked')) { | |
setChartDeltaValues(); | |
} | |
}); | |
$("#regularChartRadio").on('change', function() { | |
if($(this).is(':checked')) { | |
setChartRegularValues(); | |
} | |
}); | |
$("#derivativeChartRadio").on('change', function() { | |
if($(this).is(':checked')) { | |
setChartGrowthRateValues(); | |
} | |
}); | |
} | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var setChartDeltaValues = function() { | |
var chart = $("#chart-container").highcharts(); | |
var y_axis_max = Math.max(Math.max.apply(Math, historyCharts.total_likes_series), | |
Math.max.apply(Math, historyCharts.total_comments_series), | |
Math.max.apply(Math, historyCharts.total_shares_series)); | |
chart.series[0].setData(historyCharts.delta_likes_series, false); | |
chart.series[0].update({name: "Change in Likes"}, false); | |
chart.series[1].setData(historyCharts.delta_comments_series, false); | |
chart.series[1].update({name: "Change in Comments"}, false); | |
chart.series[2].setData(historyCharts.delta_shares_series, false); | |
chart.series[2].update({name: "Change in Shares"}, false); | |
chart.yAxis[0].setExtremes(0, y_axis_max); | |
chart.yAxis[0].setTitle({text: "Change: in Likes, Shares, Comments"}); | |
chart.redraw(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment