Skip to content

Commit

Permalink
Add data to horizontal bar 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 4f3c7e9
Showing 1 changed file with 33 additions and 1 deletion.
34 changes: 33 additions & 1 deletion ui/web/static/js/charts.js
Original file line number Diff line number Diff line change
Expand Up @@ -751,7 +751,39 @@ class HorizontalBarChart extends Echart {
]
};
horizontalBarChart.setOption(option);`;
horizontalBarChart.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 4f3c7e9

Please sign in to comment.