Skip to content

Instantly share code, notes, and snippets.

@Talon876
Last active July 1, 2016 05:36
Show Gist options
  • Save Talon876/05c560a8b4436e91b9ad0a0514d7f477 to your computer and use it in GitHub Desktop.
Save Talon876/05c560a8b4436e91b9ad0a0514d7f477 to your computer and use it in GitHub Desktop.
A rough draft implementation of persisting the zoom level and series visibility of a chart from https://rocketleaguestats.com
function createChartStatsGained(e, a) {
$.get("/api/profile/stats-gained/" + a, function(a) {
e.highcharts({
chart: {
zoomType: "x",
events: {
load: function() {
var zoomLevel = localStorage.getItem("zoom") || 0;
this.rangeSelector.clickButton(zoomLevel);
addCredits(this);
var seriesData = JSON.parse(localStorage.getItem("series")) || {};
Object.keys(seriesData).forEach(function(index) {
if (seriesData[index]) {
this.series[index].hide();
}
}.bind(this));
}
}
},
title: {
text: "Player Stats Gained",
x: -20
},
subtitle: {
text: "Updated hourly",
x: -20
},
xAxis: {
type: "datetime",
labels: {
formatter: function() {
return moment(this.value).format("YYYY-MM-DD")
}
},
events: {
setExtremes: function(e) {
if (typeof(e.rangeSelectorButton) !== 'undefined') {
localStorage.setItem("zoom", e.rangeSelectorButton.id);
}
}
}
},
yAxis: {
title: {
text: "Amount Gained"
},
plotLines: [{
value: 0,
width: 1,
color: "#808080"
}]
},
scrollbar: {
enabled: a.wins.length > 6
},
rangeSelector: {
enabled: !0,
allButtonsEnabled: !0,
buttons: [{
type: "day",
count: 7,
text: "7d",
id: 0
}, {
type: "month",
count: 1,
text: "1m",
id: 1
}, {
type: "month",
count: 3,
text: "3m",
id: 2
}, {
type: "all",
text: "All",
id: 3
}]
},
tooltip: {
headerFormat: '<span style="font-size:10px">{point.key}</span><table>',
pointFormatter: function() {
return '<tr><td style="color:' + this.color + ';padding:0;">' + this.series.name + ': </td><td style="padding:0 0 0 4px;"><strong>' + this.y + "</strong></td></tr>"
},
footerFormat: "</table>",
shared: !0,
useHTML: !0
},
legend: {
layout: "horizontal",
align: "center",
borderWidth: 0
},
series: [{
name: "Wins",
data: a.wins,
}, {
name: "Goals",
data: a.goals,
}, {
name: "MVPs",
data: a.mvps,
enabled: false,
}, {
name: "Saves",
}, {
name: "Shots",
data: a.shots,
}],
plotOptions: {
series: {
events: {
legendItemClick: function(event) {
var series = JSON.parse(localStorage.getItem("series")) || {};
series[this.index] = this.visible;
localStorage.setItem("series", JSON.stringify(series));
}
}
}
},
navigation: {
buttonOptions: {
theme: {
style: {
color: "#E0E0E0"
}
}
}
},
exporting: {
buttons: {
contextButton: getContextButton()
},
filename: "player_stats_gained_chart",
sourceWidth: 1200,
sourceHeight: 600
}
})
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment