Skip to content

Commit 1315119

Browse files
committed
Dynamic updates, rounding
1 parent 1e75bd3 commit 1315119

File tree

2 files changed

+85
-81
lines changed

2 files changed

+85
-81
lines changed

src/main/java/com/redislabs/demos/redisbank/transactions/TransactionOverviewController.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ public BiggestSpenders biggestSpenders() {
7777
BiggestSpenders biggestSpenders = new BiggestSpenders(range.size());
7878
int i = 0;
7979
for (TypedTuple<String> typedTuple : range) {
80-
biggestSpenders.getSeries()[i] = typedTuple.getScore();
80+
biggestSpenders.getSeries()[i] = Math.floor(typedTuple.getScore() * 100) / 100;
8181
biggestSpenders.getLabels()[i] = typedTuple.getValue();
8282
i++;
8383
}

src/main/resources/static/assets/js/transactions.js

Lines changed: 84 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,62 @@ var transactionsOverview = new Vue({
77
account: 'bar',
88
balance: '',
99
question: '',
10-
searchitems: []
10+
searchitems: [],
11+
areaOptions : {
12+
series: [],
13+
xaxis: {
14+
type: "datetime",
15+
},
16+
yaxis: {
17+
decimalsInFloat: 2
18+
},
19+
chart: {
20+
height: 350,
21+
type: "area",
22+
},
23+
dataLabels: {
24+
enabled: false,
25+
},
26+
stroke: {
27+
curve: "smooth",
28+
},
29+
noData: {
30+
text: 'Loading...'
31+
}
32+
},
33+
areaChart: '',
34+
pieOptions : {
35+
series: [1, 2, 3, 4, 5],
36+
chart: {
37+
height: 350,
38+
type: 'donut',
39+
options: {
40+
chart: {
41+
id: "chart-id"
42+
}
43+
}
44+
},
45+
labels: ['a', 'b', 'c', 'd', 'e'],
46+
responsive: [{
47+
breakpoint: 480,
48+
options: {
49+
chart: {
50+
width: 200,
51+
id: "chart-id"
52+
},
53+
legend: {
54+
position: 'bottom'
55+
}
56+
}
57+
}]
58+
},
59+
piechart:''
1160
},
1261
mounted() {
62+
this.areaChart = new ApexCharts(document.querySelector("#area"), this.areaOptions);
63+
this.areaChart.render()
64+
this.pieChart = new ApexCharts(document.querySelector("#chart"), this.pieOptions);
65+
this.pieChart.render()
1366
this.getTransactions()
1467
this.connect()
1568
},
@@ -56,6 +109,35 @@ var transactionsOverview = new Vue({
56109
vm.items.unshift(transactionObject)
57110
vm.account = transactionObject.toAccount
58111
vm.balance = transactionObject.balanceAfter
112+
113+
axios.get("/api/balance")
114+
.then(function (response) {
115+
vm.areaChart.updateSeries([{
116+
name: 'value',
117+
data: response.data
118+
}])
119+
})
120+
.catch(function (error) {
121+
console.log('Error! Could not reach the API. ' + error)
122+
})
123+
124+
axios.get("/api/biggestspenders")
125+
.then(function (response) {
126+
127+
vm.pieOptions.series = response.data.series
128+
vm.pieOptions.labels = response.data.labels
129+
130+
console.log('pieooptons', vm.pieOptions)
131+
132+
vm.pieChart.destroy()
133+
vm.pieChart = new ApexCharts(document.querySelector("#chart"), vm.pieOptions);
134+
vm.pieChart.render()
135+
136+
})
137+
.catch(function (error) {
138+
console.log('Error! Could not reach the API. ' + error)
139+
})
140+
59141
})
60142
},
61143
error => {
@@ -87,82 +169,4 @@ var transactionsOverview = new Vue({
87169
}
88170

89171
}
90-
})
91-
92-
var areaOptions = {
93-
series: [],
94-
xaxis: {
95-
type: "datetime",
96-
},
97-
yaxis: {
98-
decimalsInFloat: 2
99-
},
100-
chart: {
101-
height: 350,
102-
type: "area",
103-
},
104-
dataLabels: {
105-
enabled: false,
106-
},
107-
stroke: {
108-
curve: "smooth",
109-
},
110-
noData: {
111-
text: 'Loading...'
112-
}
113-
};
114-
115-
var area = new ApexCharts(document.querySelector("#area"), areaOptions);
116-
area.render();
117-
axios.get("/api/balance")
118-
.then(function (response) {
119-
area.updateSeries([{
120-
name: 'value',
121-
data: response.data
122-
}])
123-
})
124-
.catch(function (error) {
125-
console.log('Error! Could not reach the API. ' + error)
126-
})
127-
128-
var pieOptions = {
129-
series: [1,2,3,4,5],
130-
chart: {
131-
height: 350,
132-
type: 'donut',
133-
options: {
134-
chart: {
135-
id: "chart-id"
136-
}
137-
}
138-
},
139-
labels: ['a','b','c','d','e'],
140-
responsive: [{
141-
breakpoint: 480,
142-
options: {
143-
chart: {
144-
width: 200,
145-
id: "chart-id"
146-
},
147-
legend: {
148-
position: 'bottom'
149-
}
150-
}
151-
}]
152-
};
153-
154-
axios.get("/api/biggestspenders")
155-
.then(function (response) {
156-
157-
pieOptions.series = response.data.series
158-
pieOptions.labels = response.data.labels
159-
160-
console.log('pieooptons', pieOptions)
161-
162-
var chart = new ApexCharts(document.querySelector("#chart"), pieOptions);
163-
chart.render()
164-
165-
})
166-
.catch(function (error) {
167-
console.log('Error! Could not reach the API. ' + error)
168-
})
172+
})

0 commit comments

Comments
 (0)