-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathChartByRMSAllocation.vue
91 lines (88 loc) · 2.49 KB
/
ChartByRMSAllocation.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
<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: 'RMS'
}
}
],
yAxes: [
{
gridLines: {
display: true
},
scaleLabel: {
display: true,
labelString: 'Количество землетрясений'
},
ticks: {
beginAtZero: true
}
}
]
},
legend: {
display: false
}
}
}
},
methods: {
drawChart: function(params = {}) {
this.$http.get(apiSettings.endpointAnalyticsRMSAllocation, { params: params })
.then(response => {
this.chartData.datasets[0].label = 'Распределение RMS'
this.chartData.datasets[0].data = response.data.data.counts
this.chartData.labels = response.data.data.rms_values
// 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)
})
}
},
watch: {
filtersParams: function(data) {
this.drawChart(data)
}
}
})
</script>