Skip to content

Commit

Permalink
Added data to multibar chart
Browse files Browse the repository at this point in the history
Signed-off-by: felix.gateru <[email protected]>
  • Loading branch information
felixgateru committed Mar 11, 2024
1 parent 21463e5 commit ed35f00
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions ui/web/static/js/charts.js
Original file line number Diff line number Diff line change
Expand Up @@ -1022,6 +1022,37 @@ class MultiBarChart extends Echart {
]
};
multiBarChart.setOption(option);
async fetchDataAndUpdate() {
try {
const apiEndpoint = '/data?channel=${this.chartData.channel}';
const response = await fetch(apiEndpoint);
if (!response.ok) {
throw new Error('API request failed with status ${response.status}');
}
const data = await response.json();
updateChart(data);
} catch (error) {
console.error("Error fetching data:", error);
// Handle the error (e.g., display an error message)
} finally {
// Schedule the next update
setTimeout(() => this.fetchDataAndUpdate(), 5000); // Example: 5 seconds
}
}
updateChart(data) {
const barChart = echarts.init(document.getElementById(this.ID));
const option = barChart.getOption(); // Get the existing options
option.series[0].data = data.seriesData;
barChart.setOption(option); // Update the chart
}
}
`;
}
}
Expand Down

0 comments on commit ed35f00

Please sign in to comment.