|
@@ -1,5 +1,10 @@
|
|
|
<template>
|
|
<template>
|
|
|
- <canvas id="graph"></canvas>
|
|
|
|
|
|
|
+ <div class="container">
|
|
|
|
|
+ <button @click="type = 0">Day</button>
|
|
|
|
|
+ <button @click="type = 1">Month</button>
|
|
|
|
|
+ <button @click="type = 2">Year</button>
|
|
|
|
|
+ <canvas id="graph"></canvas>
|
|
|
|
|
+ </div>
|
|
|
</template>
|
|
</template>
|
|
|
<script>
|
|
<script>
|
|
|
var generateTemplate = function(){
|
|
var generateTemplate = function(){
|
|
@@ -37,7 +42,8 @@ var generateTemplate = function(){
|
|
|
this.updateData();
|
|
this.updateData();
|
|
|
},
|
|
},
|
|
|
mounted: function () {
|
|
mounted: function () {
|
|
|
- //this.update();
|
|
|
|
|
|
|
+ this.initData();
|
|
|
|
|
+ this.update();
|
|
|
},
|
|
},
|
|
|
props: {
|
|
props: {
|
|
|
server: {
|
|
server: {
|
|
@@ -52,6 +58,7 @@ var generateTemplate = function(){
|
|
|
data: function () {
|
|
data: function () {
|
|
|
return {
|
|
return {
|
|
|
chart: {},
|
|
chart: {},
|
|
|
|
|
+ type: 0,
|
|
|
// labels: {},
|
|
// labels: {},
|
|
|
stamp: null
|
|
stamp: null
|
|
|
// datasetTempalte:{
|
|
// datasetTempalte:{
|
|
@@ -78,6 +85,12 @@ var generateTemplate = function(){
|
|
|
// },
|
|
// },
|
|
|
}
|
|
}
|
|
|
},
|
|
},
|
|
|
|
|
+ watch:{
|
|
|
|
|
+ type: function () {
|
|
|
|
|
+ this.updateData(this.type);
|
|
|
|
|
+ this.update();
|
|
|
|
|
+ }
|
|
|
|
|
+ },
|
|
|
methods: {
|
|
methods: {
|
|
|
initData: function () {
|
|
initData: function () {
|
|
|
this.params = {
|
|
this.params = {
|
|
@@ -106,18 +119,22 @@ var generateTemplate = function(){
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
};
|
|
};
|
|
|
|
|
+ this.chartElement = $(this.$el).find("#graph");
|
|
|
|
|
+ console.log(this.chartElement);
|
|
|
|
|
+ this.chart = new Chart(this.chartElement, this.params);
|
|
|
},
|
|
},
|
|
|
update: function () {
|
|
update: function () {
|
|
|
if(this.maxplayers > 0){
|
|
if(this.maxplayers > 0){
|
|
|
this.params.options.scales.yAxes[0].ticks.max = parseInt(this.maxplayers);
|
|
this.params.options.scales.yAxes[0].ticks.max = parseInt(this.maxplayers);
|
|
|
- }else if(this.$root.servers[parseInt(this.$root.serversId[this.$route.params.id])].maxPlayers){
|
|
|
|
|
|
|
+ }else if(this.$root.servers &&
|
|
|
|
|
+ this.$root.servers[parseInt(this.$root.serversId[this.$route.params.id])].maxPlayers){
|
|
|
this.params.options.scales.yAxes[0].ticks.max = this.$root.servers[parseInt(this.$root.serversId[this.$route.params.id])].maxPlayers;
|
|
this.params.options.scales.yAxes[0].ticks.max = this.$root.servers[parseInt(this.$root.serversId[this.$route.params.id])].maxPlayers;
|
|
|
}
|
|
}
|
|
|
this.params.data = this.graphdata;
|
|
this.params.data = this.graphdata;
|
|
|
- this.chart = new Chart(this.$el, this.params);
|
|
|
|
|
|
|
+ this.chart.update();
|
|
|
},
|
|
},
|
|
|
- updateData: function () {
|
|
|
|
|
- this.initData();
|
|
|
|
|
|
|
+ updateData: function (type) {
|
|
|
|
|
+ type = type || 0;
|
|
|
this.graphdata = {
|
|
this.graphdata = {
|
|
|
labels: [],
|
|
labels: [],
|
|
|
datasets: [
|
|
datasets: [
|
|
@@ -143,14 +160,25 @@ var generateTemplate = function(){
|
|
|
url += month;
|
|
url += month;
|
|
|
url += "/";
|
|
url += "/";
|
|
|
url += year;
|
|
url += year;
|
|
|
- url += "/day";
|
|
|
|
|
|
|
+ switch (type) {
|
|
|
|
|
+ case 0:
|
|
|
|
|
+ url += "/day";
|
|
|
|
|
+ break;
|
|
|
|
|
+ case 1:
|
|
|
|
|
+ url += "/month";
|
|
|
|
|
+ break;
|
|
|
|
|
+ case 2:
|
|
|
|
|
+ url += "/year";
|
|
|
|
|
+ break;
|
|
|
|
|
+ default:
|
|
|
|
|
+ url += "/day";
|
|
|
|
|
+ }
|
|
|
// console.log(url);
|
|
// console.log(url);
|
|
|
$.getJSON(url)
|
|
$.getJSON(url)
|
|
|
.done(function (obj) {
|
|
.done(function (obj) {
|
|
|
if(obj.length <= 0){
|
|
if(obj.length <= 0){
|
|
|
return -1;
|
|
return -1;
|
|
|
}
|
|
}
|
|
|
- console.log(self);
|
|
|
|
|
self.graphdata.datasets[0].data = [];
|
|
self.graphdata.datasets[0].data = [];
|
|
|
self.graphdata.datasets = [];
|
|
self.graphdata.datasets = [];
|
|
|
var firstStamp = new Date(obj[0].createdAt);
|
|
var firstStamp = new Date(obj[0].createdAt);
|