Skip to content
Snippets Groups Projects
Commit 7dc73cff authored by Robert Goldmann's avatar Robert Goldmann
Browse files

Fixed #28 - add charts

added barchart and linechart
parent e7691340
Branches
Tags
2 merge requests!104merge v_1_2_0 into master,!100merge charts into v_1_2_0
......@@ -5,6 +5,7 @@ import java.net.URLEncoder;
import java.text.DecimalFormat;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
public class Helpers
{
......@@ -31,4 +32,32 @@ public class Helpers
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
return date.format(formatter);
}
public static ArrayList<String> getMonthList()
{
ArrayList<String> monthNames = new ArrayList<>();
monthNames.add("Januar");
monthNames.add("Februar");
monthNames.add("März");
monthNames.add("April");
monthNames.add("Mai");
monthNames.add("Juni");
monthNames.add("Juli");
monthNames.add("August");
monthNames.add("September");
monthNames.add("Oktober");
monthNames.add("November");
monthNames.add("Dezember");
return monthNames;
}
public static ArrayList<String> getYearList()
{
ArrayList<String> years = new ArrayList<>();
for(int i = 2000; i < 2100; i++)
{
years.add(String.valueOf(i));
}
return years;
}
}
\ No newline at end of file
......@@ -27,7 +27,7 @@ public class Main extends Application
FXMLLoader loader = new FXMLLoader(getClass().getClassLoader().getResource("de/deadlocker8/budgetmaster/ui/GUI.fxml"));
Parent root = (Parent)loader.load();
Scene scene = new Scene(root, 600, 650);
Scene scene = new Scene(root, 650, 650);
((Controller)loader.getController()).init(stage);
......
......@@ -4,8 +4,10 @@ import java.time.LocalDate;
import java.util.ArrayList;
import org.joda.time.DateTime;
import org.joda.time.format.DateTimeFormat;
import de.deadlocker8.budgetmaster.logic.CategoryInOutSum;
import de.deadlocker8.budgetmaster.logic.Helpers;
import de.deadlocker8.budgetmaster.logic.MonthInOutSum;
import de.deadlocker8.budgetmaster.logic.ServerConnection;
import de.deadlocker8.budgetmaster.logic.chartGenerators.BarChartGenerator;
......@@ -13,18 +15,24 @@ import de.deadlocker8.budgetmaster.logic.chartGenerators.LineChartGenerator;
import de.deadlocker8.budgetmaster.logic.chartGenerators.PieChartGenerator;
import fontAwesome.FontIcon;
import fontAwesome.FontIconType;
import javafx.collections.FXCollections;
import javafx.fxml.FXML;
import javafx.scene.chart.BarChart;
import javafx.scene.chart.LineChart;
import javafx.scene.control.Accordion;
import javafx.scene.control.Alert.AlertType;
import javafx.scene.control.Button;
import javafx.scene.control.ComboBox;
import javafx.scene.control.DateCell;
import javafx.scene.control.DatePicker;
import javafx.scene.control.RadioButton;
import javafx.scene.control.ToggleGroup;
import javafx.scene.layout.AnchorPane;
import javafx.scene.layout.HBox;
import javafx.scene.paint.Color;
import javafx.util.Callback;
import logger.Logger;
import tools.AlertGenerator;
public class ChartController implements Refreshable
{
......@@ -34,8 +42,14 @@ public class ChartController implements Refreshable
@FXML private HBox hboxChartCategories;
@FXML private DatePicker datePickerEnd;
@FXML private AnchorPane anchorPaneChartMonth;
@FXML private AnchorPane anchorPaneLineChart;
@FXML private Button buttonChartCategoriesShow;
@FXML private ComboBox<String> comboBoxStartMonth;
@FXML private ComboBox<String> comboBoxStartYear;
@FXML private ComboBox<String> comboBoxEndMonth;
@FXML private ComboBox<String> comboBoxEndYear;
@FXML private Button buttonChartMonthShow;
@FXML private RadioButton radioButtonBars;
@FXML private RadioButton radioButtonLines;
private Controller controller;
......@@ -52,6 +66,12 @@ public class ChartController implements Refreshable
buttonChartCategoriesShow.setStyle("-fx-background-color: #2E79B9;");
buttonChartCategoriesShow.setGraphic(iconShow);
FontIcon iconShow2 = new FontIcon(FontIconType.CHECK);
iconShow2.setSize(16);
iconShow2.setColor(Color.WHITE);
buttonChartMonthShow.setStyle("-fx-background-color: #2E79B9;");
buttonChartMonthShow.setGraphic(iconShow2);
datePickerEnd.setDayCellFactory(new Callback<DatePicker, DateCell>()
{
@Override
......@@ -72,6 +92,23 @@ public class ChartController implements Refreshable
};
}
});
comboBoxStartMonth.setItems(FXCollections.observableArrayList(Helpers.getMonthList()));
comboBoxStartMonth.setValue(controller.getCurrentDate().minusMonths(5).toString("MMMM"));
comboBoxStartYear.setItems(FXCollections.observableArrayList(Helpers.getYearList()));
comboBoxStartYear.setValue(String.valueOf(controller.getCurrentDate().minusMonths(5).getYear()));
comboBoxEndMonth.setItems(FXCollections.observableArrayList(Helpers.getMonthList()));
comboBoxEndMonth.setValue(controller.getCurrentDate().plusMonths(6).toString("MMMM"));
comboBoxEndYear.setItems(FXCollections.observableArrayList(Helpers.getYearList()));
comboBoxEndYear.setValue(String.valueOf(controller.getCurrentDate().plusMonths(6).getYear()));
final ToggleGroup toggleGroup = new ToggleGroup();
radioButtonBars.setToggleGroup(toggleGroup);
radioButtonBars.setSelected(true);
radioButtonLines.setToggleGroup(toggleGroup);
}
public void chartCategoriesShow()
......@@ -101,24 +138,38 @@ public class ChartController implements Refreshable
public void chartMonthShow()
{
//DEBUG get date from comboboxes
DateTime startDate = controller.getCurrentDate().withMonthOfYear(1);
DateTime endDate = controller.getCurrentDate().withMonthOfYear(12);
anchorPaneChartMonth.getChildren().clear();
String startMonth = comboBoxStartMonth.getValue();
String startYear = comboBoxStartYear.getValue();
String endMonth = comboBoxEndMonth.getValue();
String endYear = comboBoxEndYear.getValue();
String startDateString = "01-" + startMonth + "-" + startYear;
DateTime startDate = DateTime.parse(startDateString, DateTimeFormat.forPattern("dd-MMMM-YYYY"));
String endDateString = "01-" + endMonth + "-" + endYear;
DateTime endDate = DateTime.parse(endDateString, DateTimeFormat.forPattern("dd-MMMM-YYYY"));
if(endDate.isBefore(startDate))
{
AlertGenerator.showAlert(AlertType.WARNING, "Warnung", "", "Das Enddatum darf nicht vor dem Startdatum liegen.", controller.getIcon(), controller.getStage(), null, false);
return;
}
try
{
ServerConnection connection = new ServerConnection(controller.getSettings());
//DEBUG
ArrayList<MonthInOutSum> sums = connection.getMonthInOutSum(startDate, endDate);
anchorPaneChartMonth.getChildren().clear();
BarChartGenerator generator = new BarChartGenerator(sums, controller.getSettings().getCurrency());
BarChart<String, Number> chartMonth = generator.generate();
anchorPaneChartMonth.getChildren().add(chartMonth);
AnchorPane.setTopAnchor(chartMonth, 0.0);
AnchorPane.setRightAnchor(chartMonth, 0.0);
AnchorPane.setBottomAnchor(chartMonth, 0.0);
AnchorPane.setLeftAnchor(chartMonth, 0.0);
if(radioButtonBars.isSelected())
{
chartMonthBarShow(sums);
}
else
{
chartMonthLineShow(sums);
}
}
catch(Exception e)
{
......@@ -128,34 +179,29 @@ public class ChartController implements Refreshable
}
}
public void chartLineChartShow()
public void chartMonthBarShow(ArrayList<MonthInOutSum> sums)
{
//DEBUG get date from comboboxes
DateTime startDate = controller.getCurrentDate().withMonthOfYear(1);
DateTime endDate = controller.getCurrentDate().withMonthOfYear(12);
try
{
ServerConnection connection = new ServerConnection(controller.getSettings());
//DEBUG
ArrayList<MonthInOutSum> sums = connection.getMonthInOutSum(startDate, endDate);
BarChartGenerator generator = new BarChartGenerator(sums, controller.getSettings().getCurrency());
BarChart<String, Number> chartMonth = generator.generate();
anchorPaneChartMonth.getChildren().add(chartMonth);
AnchorPane.setTopAnchor(chartMonth, 0.0);
AnchorPane.setRightAnchor(chartMonth, 0.0);
AnchorPane.setBottomAnchor(chartMonth, 0.0);
AnchorPane.setLeftAnchor(chartMonth, 0.0);
}
anchorPaneLineChart.getChildren().clear();
public void chartMonthLineShow(ArrayList<MonthInOutSum> sums)
{
anchorPaneChartMonth.getChildren().clear();
LineChartGenerator generator = new LineChartGenerator(sums, controller.getSettings().getCurrency());
LineChart<String, Number> chartMonth = generator.generate();
anchorPaneLineChart.getChildren().add(chartMonth);
anchorPaneChartMonth.getChildren().add(chartMonth);
AnchorPane.setTopAnchor(chartMonth, 0.0);
AnchorPane.setRightAnchor(chartMonth, 0.0);
AnchorPane.setBottomAnchor(chartMonth, 0.0);
AnchorPane.setLeftAnchor(chartMonth, 0.0);
}
catch(Exception e)
{
Logger.error(e);
//TODO
//controller.showConnectionErrorAlert(e.getMessage());
}
}
@Override
public void refresh()
......@@ -172,8 +218,6 @@ public class ChartController implements Refreshable
// chart month
chartMonthShow();
chartLineChartShow();
// TODO combine bar und line chart (radio buttons)
accordion.setExpandedPane(accordion.getPanes().get(0));
......
......@@ -6,6 +6,7 @@
<?import javafx.scene.control.ComboBox?>
<?import javafx.scene.control.DatePicker?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.control.RadioButton?>
<?import javafx.scene.control.TitledPane?>
<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.layout.HBox?>
......@@ -73,99 +74,57 @@
<content>
<VBox spacing="20.0">
<children>
<HBox alignment="CENTER" prefHeight="8.0" prefWidth="750.0">
<HBox alignment="CENTER_LEFT" prefHeight="8.0" prefWidth="750.0" spacing="50.0">
<children>
<HBox alignment="CENTER_RIGHT" spacing="10.0" HBox.hgrow="ALWAYS">
<VBox spacing="15.0">
<children>
<Label text="Von:">
<HBox alignment="CENTER_RIGHT" spacing="10.0">
<children>
<Label prefHeight="25.0" prefWidth="45.0" text="Von:">
<font>
<Font name="System Bold" size="16.0" />
</font>
</Label>
<ComboBox prefHeight="25.0" prefWidth="100.0" />
<ComboBox prefWidth="70.0" />
<ComboBox fx:id="comboBoxStartMonth" prefHeight="25.0" prefWidth="110.0" />
<ComboBox fx:id="comboBoxStartYear" prefWidth="70.0" />
</children>
<HBox.margin>
<Insets right="15.0" />
</HBox.margin>
</HBox>
<HBox alignment="CENTER_LEFT" spacing="10.0" HBox.hgrow="ALWAYS">
<HBox alignment="CENTER_LEFT" spacing="10.0">
<children>
<Label text="Bis:">
<Label prefWidth="45.0" text="Bis:">
<font>
<Font name="System Bold" size="16.0" />
</font>
</Label>
<ComboBox prefWidth="100.0" />
<ComboBox prefWidth="70.0" />
<Button fx:id="buttonChartCategoriesShow1" mnemonicParsing="false" onAction="#chartCategoriesShow">
<font>
<Font name="System Bold" size="12.0" />
</font>
<HBox.margin>
<Insets left="15.0" />
</HBox.margin>
</Button>
<ComboBox fx:id="comboBoxEndMonth" prefWidth="110.0" />
<ComboBox fx:id="comboBoxEndYear" prefWidth="70.0" />
</children>
<HBox.margin>
<Insets left="15.0" />
</HBox.margin>
</HBox>
</children>
</HBox>
<AnchorPane fx:id="anchorPaneChartMonth" prefHeight="200.0" prefWidth="200.0" VBox.vgrow="ALWAYS" />
</children>
</VBox>
</content>
</TitledPane>
<TitledPane animated="false" text="Einnahmen/Ausgaben pro Monat Verlauf">
<font>
<Font name="System Bold" size="12.0" />
</font>
<content>
<VBox spacing="20.0">
<children>
<HBox alignment="CENTER" prefHeight="8.0" prefWidth="750.0">
<HBox alignment="CENTER_LEFT" spacing="15.0" HBox.hgrow="ALWAYS">
<children>
<HBox alignment="CENTER_RIGHT" spacing="10.0" HBox.hgrow="ALWAYS">
<children>
<Label text="Von:">
<RadioButton fx:id="radioButtonBars" mnemonicParsing="false" text="Balken">
<font>
<Font name="System Bold" size="16.0" />
</font>
</Label>
<ComboBox prefHeight="25.0" prefWidth="100.0" />
<ComboBox prefWidth="70.0" />
</children>
<HBox.margin>
<Insets right="15.0" />
</HBox.margin>
</HBox>
<HBox alignment="CENTER_LEFT" spacing="10.0" HBox.hgrow="ALWAYS">
<children>
<Label text="Bis:">
<Font size="14.0" />
</font></RadioButton>
<RadioButton fx:id="radioButtonLines" mnemonicParsing="false" text="Linien">
<font>
<Font name="System Bold" size="16.0" />
</font>
</Label>
<ComboBox prefWidth="100.0" />
<ComboBox prefWidth="70.0" />
<Button fx:id="buttonChartCategoriesShow11" mnemonicParsing="false" onAction="#chartCategoriesShow">
<Font size="14.0" />
</font></RadioButton>
<Button fx:id="buttonChartMonthShow" mnemonicParsing="false" onAction="#chartMonthShow">
<font>
<Font name="System Bold" size="12.0" />
</font>
<HBox.margin>
<Insets left="15.0" />
<Insets left="10.0" />
</HBox.margin>
</Button>
</children>
<HBox.margin>
<Insets left="15.0" />
</HBox.margin>
</HBox>
</children>
</HBox>
<AnchorPane fx:id="anchorPaneLineChart" prefHeight="200.0" prefWidth="200.0" VBox.vgrow="ALWAYS" />
<AnchorPane fx:id="anchorPaneChartMonth" prefHeight="200.0" prefWidth="200.0" VBox.vgrow="ALWAYS" />
</children>
</VBox>
</content>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment