mirror of
https://github.com/pcvolkmer/etl-processor.git
synced 2025-07-02 06:22:55 +00:00
(Near) realtime update of statistics charts
This commit is contained in:
@ -13,101 +13,144 @@ window.onload = () => {
|
||||
});
|
||||
};
|
||||
|
||||
function drawPieChart(url, elemId, title) {
|
||||
fetch(url)
|
||||
.then(resp => resp.json())
|
||||
.then(data => {
|
||||
let chartDom = document.getElementById(elemId);
|
||||
let chart = echarts.init(chartDom);
|
||||
let option= {
|
||||
title: {
|
||||
text: title,
|
||||
left: 'center'
|
||||
},
|
||||
tooltip: {
|
||||
trigger: 'item'
|
||||
},
|
||||
color: data.map(i => i.color),
|
||||
series: [
|
||||
{
|
||||
type: 'pie',
|
||||
radius: ['40%', '70%'],
|
||||
avoidLabelOverlap: false,
|
||||
label: {
|
||||
show: false,
|
||||
position: 'center'
|
||||
},
|
||||
labelLine: {
|
||||
show: false
|
||||
},
|
||||
data: data
|
||||
}
|
||||
]
|
||||
};
|
||||
function drawPieChart(url, elemId, title, data) {
|
||||
if (data) {
|
||||
update(elemId, data);
|
||||
} else {
|
||||
fetch(url)
|
||||
.then(resp => resp.json())
|
||||
.then(d => {
|
||||
draw(elemId, title, d);
|
||||
update(elemId, d);
|
||||
});
|
||||
}
|
||||
|
||||
option && chart.setOption(option);
|
||||
});
|
||||
function update(elemId, data) {
|
||||
let chartDom = document.getElementById(elemId);
|
||||
let chart = echarts.init(chartDom);
|
||||
|
||||
let option = {
|
||||
color: data.map(i => i.color),
|
||||
animationDuration: 250,
|
||||
animationDurationUpdate: 250,
|
||||
series: [
|
||||
{
|
||||
type: 'pie',
|
||||
radius: ['40%', '70%'],
|
||||
avoidLabelOverlap: false,
|
||||
label: {
|
||||
show: false,
|
||||
position: 'center'
|
||||
},
|
||||
labelLine: {
|
||||
show: false
|
||||
},
|
||||
data: data
|
||||
}
|
||||
]
|
||||
};
|
||||
|
||||
option && chart.setOption(option);
|
||||
}
|
||||
|
||||
function draw(elemId, title, data) {
|
||||
let chartDom = document.getElementById(elemId);
|
||||
let chart = echarts.init(chartDom);
|
||||
let option= {
|
||||
title: {
|
||||
text: title,
|
||||
left: 'center'
|
||||
},
|
||||
tooltip: {
|
||||
trigger: 'item'
|
||||
},
|
||||
color: data.map(i => i.color),
|
||||
animationDuration: 250,
|
||||
animationDurationUpdate: 250
|
||||
};
|
||||
|
||||
option && chart.setOption(option);
|
||||
}
|
||||
}
|
||||
|
||||
function drawBarChart(url, elemId, title) {
|
||||
fetch(url)
|
||||
.then(resp => resp.json())
|
||||
.then(data => {
|
||||
let chartDom = document.getElementById(elemId);
|
||||
let chart = echarts.init(chartDom);
|
||||
let option= {
|
||||
title: {
|
||||
text: title,
|
||||
left: 'center'
|
||||
},
|
||||
xAxis: {
|
||||
type: 'category',
|
||||
data: data.map(i => dateFormat.format(Date.parse(i.date)))
|
||||
},
|
||||
yAxis: {
|
||||
type: 'value',
|
||||
minInterval: 2,
|
||||
},
|
||||
tooltip: {
|
||||
trigger: 'item'
|
||||
},
|
||||
animation: false,
|
||||
color: ['slategray', 'red', 'darkorange', 'green', 'slategray'],
|
||||
series: [
|
||||
{
|
||||
name: 'UNKNOWN',
|
||||
type: 'bar',
|
||||
stack: 'total',
|
||||
data: data.map(i => i.nameValues.unknown)
|
||||
},
|
||||
{
|
||||
name: 'ERROR',
|
||||
type: 'bar',
|
||||
stack: 'total',
|
||||
data: data.map(i => i.nameValues.error)
|
||||
},
|
||||
{
|
||||
name: 'WARNING',
|
||||
type: 'bar',
|
||||
stack: 'total',
|
||||
data: data.map(i => i.nameValues.warning)
|
||||
},
|
||||
{
|
||||
name: 'SUCCESS',
|
||||
type: 'bar',
|
||||
stack: 'total',
|
||||
data: data.map(i => i.nameValues.success)
|
||||
},
|
||||
{
|
||||
name: 'DUPLICATION',
|
||||
type: 'bar',
|
||||
stack: 'total',
|
||||
data: data.map(i => i.nameValues.duplication)
|
||||
}
|
||||
]
|
||||
};
|
||||
function drawBarChart(url, elemId, title, data) {
|
||||
if (data) {
|
||||
update(elemId, data);
|
||||
} else {
|
||||
fetch(url)
|
||||
.then(resp => resp.json())
|
||||
.then(data => {
|
||||
draw(elemId, title, data);
|
||||
update(elemId, data);
|
||||
});
|
||||
}
|
||||
|
||||
option && chart.setOption(option);
|
||||
});
|
||||
function update(elemId, data) {
|
||||
let chartDom = document.getElementById(elemId);
|
||||
let chart = echarts.init(chartDom);
|
||||
|
||||
let option = {
|
||||
series: [
|
||||
{
|
||||
name: 'UNKNOWN',
|
||||
type: 'bar',
|
||||
stack: 'total',
|
||||
data: data.map(i => i.nameValues.unknown)
|
||||
},
|
||||
{
|
||||
name: 'ERROR',
|
||||
type: 'bar',
|
||||
stack: 'total',
|
||||
data: data.map(i => i.nameValues.error)
|
||||
},
|
||||
{
|
||||
name: 'WARNING',
|
||||
type: 'bar',
|
||||
stack: 'total',
|
||||
data: data.map(i => i.nameValues.warning)
|
||||
},
|
||||
{
|
||||
name: 'SUCCESS',
|
||||
type: 'bar',
|
||||
stack: 'total',
|
||||
data: data.map(i => i.nameValues.success)
|
||||
},
|
||||
{
|
||||
name: 'DUPLICATION',
|
||||
type: 'bar',
|
||||
stack: 'total',
|
||||
data: data.map(i => i.nameValues.duplication)
|
||||
}
|
||||
]
|
||||
};
|
||||
|
||||
option && chart.setOption(option);
|
||||
}
|
||||
|
||||
function draw(elemId, title, data) {
|
||||
let chartDom = document.getElementById(elemId);
|
||||
let chart = echarts.init(chartDom);
|
||||
let option= {
|
||||
title: {
|
||||
text: title,
|
||||
left: 'center'
|
||||
},
|
||||
xAxis: {
|
||||
type: 'category',
|
||||
data: data.map(i => dateFormat.format(Date.parse(i.date)))
|
||||
},
|
||||
yAxis: {
|
||||
type: 'value',
|
||||
minInterval: 1
|
||||
},
|
||||
tooltip: {
|
||||
trigger: 'item'
|
||||
},
|
||||
color: ['slategray', 'red', 'darkorange', 'green', 'slategray'],
|
||||
animationDuration: 250,
|
||||
animationDurationUpdate: 250
|
||||
};
|
||||
|
||||
option && chart.setOption(option);
|
||||
}
|
||||
}
|
@ -17,8 +17,18 @@
|
||||
<script th:src="@{/echarts.min.js}"></script>
|
||||
<script th:src="@{/scripts.js}"></script>
|
||||
<script>
|
||||
drawPieChart('statistics/requeststates', 'piechart', 'Statusverteilung der Anfragen');
|
||||
drawBarChart('statistics/requestslastmonth', 'barchart', 'Anfragen des letzten Monats');
|
||||
window.onload = () => {
|
||||
drawPieChart('statistics/requeststates', 'piechart', 'Statusverteilung aller Anfragen');
|
||||
drawBarChart('statistics/requestslastmonth', 'barchart', 'Anfragen der letzten 30 Tage');
|
||||
|
||||
const eventSource = new EventSource('statistics/events');
|
||||
eventSource.addEventListener('requeststates', event => {
|
||||
drawPieChart('statistics/requeststates', 'piechart', 'Statusverteilung aller Anfragen', JSON.parse(event.data));
|
||||
});
|
||||
eventSource.addEventListener('requestslastmonth', event => {
|
||||
drawBarChart('statistics/requestslastmonth', 'barchart', 'Anfragen des letzten Monats', JSON.parse(event.data));
|
||||
});
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
Reference in New Issue
Block a user