-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathChartByDatetime.vue
110 lines (103 loc) · 3.1 KB
/
ChartByDatetime.vue
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
<script>
import { Line } from 'vue-chartjs'
import apiSettings from '@/settings/api'
export default Line.extend({
props: ['filtersParams'],
data() {
return {
chartData: {
datasets: [{
label: '',
data: [],
fill: true,
lineTension: 0.1,
backgroundColor: 'rgba(51,122,183,0.4)',
borderColor: 'rgba(51,122,183,1)',
borderCapStyle: 'butt',
borderDash: [],
borderDashOffset: 0.0,
borderJoinStyle: 'miter',
pointBorderColor: 'rgba(51,122,183,1)',
pointBackgroundColor: 'rgba(51,122,183,1)',
pointBorderWidth: 1,
pointHoverRadius: 5,
pointHoverBackgroundColor: 'rgba(51,122,183,1)',
pointHoverBorderColor: 'rgba(51,122,183,1)',
pointHoverBorderWidth: 2,
pointRadius: 1,
pointHitRadius: 10
}],
labels: []
},
options: {
scales: {
xAxes: [
{
gridLines: {
display: true
},
scaleLabel: {
display: true,
labelString: 'Временной период'
}
}
],
yAxes: [
{
gridLines: {
display: true
},
scaleLabel: {
display: true,
labelString: 'Количество землетрясений'
},
ticks: {
beginAtZero: true
}
}
]
},
legend: {
display: false
}
}
}
},
methods: {
drawChart: function(params = {}) {
this.$http.get(apiSettings.endpointAnalyticsEarthquakeCounts, { params: params })
.then(response => {
const respData = response.data.data
const dates = this.prepareDates(respData.dates)
this.chartData.datasets[0].label = 'Количество землетрясений'
this.chartData.datasets[0].data = respData.counts
this.chartData.labels = dates
// Pass data to the Analytics.vue component.
this.$emit('update', {
eventsCount: respData.total_count,
startDate: this.$moment(respData.range.start).format('L'),
endDate: this.$moment(respData.range.end).format('L')
})
// Ugly hack to prevent showing old data on hovering.
// No idea why it doesn't covered by https://github.com/apertureless/vue-chartjs/blob/master/src/BaseCharts.js#L71
// So ¯\_(ツ)_/¯
// https://github.com/geophystech/eqalert.ru/issues/258
if (this._chart) this._chart.destroy()
this.renderChart(this.chartData, this.options)
})
},
prepareDates: function(dates) {
return dates.map(date => {
let _date = this.$moment(date).format('MMMM YYYY')
_date = _date[0].toUpperCase() + _date.substr(1)
return _date
})
}
},
watch: {
filtersParams: function(data) {
this.drawChart(data)
}
}
})
</script>