fix: improved tooltip of graph

This commit is contained in:
filippo-ferrari 2024-09-12 19:35:44 +02:00
parent edff838299
commit 0702bddc6c

View file

@ -207,8 +207,7 @@ public class DashboardView extends Div {
StringBuilder data = new StringBuilder("["); StringBuilder data = new StringBuilder("[");
for (Map.Entry<String, Double> entry : personData.entrySet()) { for (Map.Entry<String, Double> entry : personData.entrySet()) {
double value = entry.getValue(); double value = entry.getValue();
// Green for positive (credits) and red for negative (debits) String color = value >= 0 ? "#90EE90" : "#FF9999"; // Green for positive, red for negative
String color = value >= 0 ? "#90EE90" : "#FF9999";
data.append("{ y: ").append(value).append(", color: '").append(color).append("' },"); data.append("{ y: ").append(value).append(", color: '").append(color).append("' },");
} }
data.setCharAt(data.length() - 1, ']'); // Replace the last comma with a closing bracket data.setCharAt(data.length() - 1, ']'); // Replace the last comma with a closing bracket
@ -237,14 +236,22 @@ public class DashboardView extends Div {
"plotOptions: {" + "plotOptions: {" +
"column: {" + "column: {" +
"pointWidth: 50," + "pointWidth: 50," +
"threshold: 0" + // Ensure columns are drawn correctly from the zero line "threshold: 0" +
"}" +
"}," +
"tooltip: {" + // Combine default point format with a custom label
"useHTML: true," +
"formatter: function() {" +
"var label = this.y >= 0 ? 'Credit: ' : 'Debit: '; " +
"return '<span style=\"color:' + this.point.color + '\">\u25CF</span> ' + '<b>' + this.x + '</b><br/>' + label + Math.abs(this.y);" +
"}" + "}" +
"}," + "}," +
"series: [{" + "series: [{" +
"name: 'Balance'," + "name: 'Balance'," +
"data: " + data + // Use the data fetched from DB "data: " + data +
"}]" + "}]" +
"});"; } "});";
}
private String generatePlaceholderChartScript(String divId, String title) { private String generatePlaceholderChartScript(String divId, String title) {
return "Highcharts.chart('" + divId + "', {" + return "Highcharts.chart('" + divId + "', {" +