From edff838299dd5a6b76ebe393c33279d5fa3c7e3f Mon Sep 17 00:00:00 2001 From: filippo-ferrari Date: Thu, 12 Sep 2024 19:29:45 +0200 Subject: [PATCH] fix: inverted columns of graph --- .../munera/views/dashboard/DashboardView.java | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/application/munera/views/dashboard/DashboardView.java b/src/main/java/com/application/munera/views/dashboard/DashboardView.java index b23604b..dc1e968 100644 --- a/src/main/java/com/application/munera/views/dashboard/DashboardView.java +++ b/src/main/java/com/application/munera/views/dashboard/DashboardView.java @@ -199,28 +199,30 @@ public class DashboardView extends Div { for (Person person : people) { BigDecimal balance = personService.calculateNetBalance(person); - personData.put(person.getFirstName(), balance.doubleValue()); + // Invert the balance value + personData.put(person.getFirstName(), balance.negate().doubleValue()); } // Prepare series data for Highcharts with conditional coloring StringBuilder data = new StringBuilder("["); for (Map.Entry entry : personData.entrySet()) { double value = entry.getValue(); - String color = value >= 0 ? "#FF9999" : "#90EE90"; // Green for positive, red for negative + // Green for positive (credits) and red for negative (debits) + String color = value >= 0 ? "#90EE90" : "#FF9999"; data.append("{ y: ").append(value).append(", color: '").append(color).append("' },"); } - data.setCharAt(data.length() - 1, ']'); // Replace last comma with closing bracket + data.setCharAt(data.length() - 1, ']'); // Replace the last comma with a closing bracket // Generate JavaScript initialization return "Highcharts.chart('bottomLeftChart', {" + "chart: {" + - "type: 'column'," + // Specify the chart type as column + "type: 'column'," + "}," + "title: {" + "text: 'Net Balances by Person'" + "}," + "xAxis: {" + - "categories: " + new Gson().toJson(personData.keySet()) + // Categories are the person names + "categories: " + new Gson().toJson(personData.keySet()) + "}," + "yAxis: {" + "title: {" + @@ -232,9 +234,10 @@ public class DashboardView extends Div { "color: '#808080'" + "}]" + "}," + - "plotOptions: {" + // Add plotOptions to configure the column width + "plotOptions: {" + "column: {" + - "pointWidth: 50" + // Adjust the width of the columns (in pixels) + "pointWidth: 50," + + "threshold: 0" + // Ensure columns are drawn correctly from the zero line "}" + "}," + "series: [{" +