Skip to content
Snippets Groups Projects
Commit 8d0e638e authored by Eilert Tunheim's avatar Eilert Tunheim
Browse files

Updated linechart class to seperate the series from one single to multiple series

parent 20055e23
No related branches found
No related tags found
No related merge requests found
......@@ -29,7 +29,7 @@ public final class Constants {
public static final String PROJECT_ID = "sf-drying-optimization";
/*
// Location Valasen(124)
// Project settings
public static final int LOCATION_ID = 124;
......@@ -53,12 +53,12 @@ public final class Constants {
//public static final int VALUE_ID = 56; // Kammer 6
public static final int LIMIT = 1000;
*/
/*
// Location Arjang(174)
// Project settings
public static final int LOCATION_ID = 174;
......@@ -71,8 +71,8 @@ public final class Constants {
public static final String START_DRYING_NAME = "DryingStarted";
public static final String STOP_DRYING_NAME = "DryingCompleted";
public static final String KILIN_NAME = "KilinId";
//public static int KILIN_ID = 18;
public static int KILIN_ID = 18554;
public static int KILIN_ID = 18;
//public static int KILIN_ID = 18554;
// Swappconsensordata
public static final String KWH_NAME = "RealValue";
......@@ -82,6 +82,8 @@ public final class Constants {
public static final int LIMIT = 1000;
*/
......
......@@ -132,10 +132,10 @@ public class DB {
* @return the results
* @throws Exception returns potential error
*/
public static Map<Integer, Map> getKwh() throws Exception {
public static Map<Integer, Map<String, Number>> getKwh() throws Exception {
// Initializing the data map to store the results
Map<Integer, Map> finalResults = new HashMap<>();
Map<Integer, Map<String, Number>> finalResults = new HashMap<>();
int index = 0;
......@@ -201,10 +201,10 @@ public class DB {
System.out.println("\nFinal results size: "+finalResults.size());
// Defining a treemap to sort the data incrementally
NavigableMap<Integer, Map> sortedFinalResults = new TreeMap<>(finalResults);
NavigableMap<Integer, Map<String, Number>> sortedFinalResults = new TreeMap<>(finalResults);
for (Map.Entry<Integer, Map> entry : sortedFinalResults.entrySet()) {
for (Map.Entry<Integer, Map<String, Number>> entry : sortedFinalResults.entrySet()) {
System.out.printf("Timestamp: \t%s\t\t\tkWh: \t%s\n",entry.getKey(),entry.getValue());
}
......
......@@ -9,6 +9,8 @@ import javafx.stage.*;
import static com.application.DB.Constants.*;
import com.application.Main;
import javax.sound.sampled.Line;
/**
* This class handles the popup input window
*
......@@ -79,6 +81,7 @@ public class InputPopUpWindow {
// Call på getKwh()
try {
LineChartFunctionality.loadData();
//Main.createLineChart();
} catch (Exception ex) {
ex.printStackTrace();
......
package com.application.GUI;
import com.application.DB.DB;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.scene.chart.CategoryAxis;
import javafx.scene.chart.LineChart;
import javafx.scene.chart.NumberAxis;
import javafx.scene.chart.XYChart;
import java.util.Map;
public class LineChartFunctionality {
private LineChart<String, Number> lineChart;
private XYChart.Series<String, Number> series;
private final CategoryAxis xAxis;
private final NumberAxis yAxis;
private static LineChart<String, Number> lineChart;
private static XYChart.Series<String, Number> series;
private static XYChart.Data<String, Number> chartData;
private static CategoryAxis xAxis;
private static NumberAxis yAxis;
public LineChartFunctionality(){
this.xAxis = new CategoryAxis();
this.yAxis = new NumberAxis();
this.series = new XYChart.Series<String, Number>();
this.lineChart = new LineChart<>(xAxis,yAxis);
this.lineChart.getData().add(series);
this.xAxis.setLabel("Date");
this.yAxis.setLabel("Kwh");
this.lineChart.setTitle("Drying Processes");
xAxis = new CategoryAxis();
yAxis = new NumberAxis();
series = new XYChart.Series<String, Number>();
chartData = new XYChart.Data<String, Number>();
lineChart = new LineChart<>(xAxis,yAxis);
xAxis.setLabel("Date");
yAxis.setLabel("Kwh");
lineChart.setTitle("Drying Processes");
}
public LineChart<String, Number> getLineChart() {
return this.lineChart;
return lineChart;
}
public void setLineChart(LineChart<String, Number> lineChart) {
this.lineChart = lineChart;
public static XYChart.Series<String, Number> getSeries() {
return series;
}
public XYChart.Series<String, Number> getSeries() {
return this.series;
public static void updateLineChart(XYChart.Series<String, Number> series){
lineChart.getData().add(series);
}
public void setSeries(XYChart.Series<String, Number> series) {
this.series = series;
this.lineChart.getData().add(series);
public static void loadData() throws Exception {
Map<Integer, Map<String, Number>> kWh = DB.getKwh();
//System.out.println(kWh.size());
for (Map.Entry<Integer, Map<String, Number>> entryKwh : kWh.entrySet()) {
Map data = entryKwh.getValue();
//System.out.println(data.size());
XYChart.Series<String, Number> newSeries = new XYChart.Series<String, Number>();
for (Object entryData : data.entrySet()){
//System.out.println("data: \t"+entryData);
String entryString = entryData.toString();
String[] arr = entryString.split("=");
String date = arr[0];
int kwhValue = Integer.parseInt(arr[1]);
//System.out.printf("Date: \t%s\t\t\tkWh: \t%s\n",date,kwhValue);
// Connect the data to a series
newSeries.getData().add(new XYChart.Data<String, Number>(date,kwhValue));
}
updateLineChart(newSeries);
}
/*
for (Map.Entry<Integer, Map> entryKwh : kWh.entrySet()) {
System.out.printf("Index: \t%s\t\t\tkWh: \t%s\n",entryKwh.getKey(),entryKwh.getValue());
}
*/
}
}
......@@ -266,40 +266,6 @@ public class Main extends Application {
return new HBox(imageViewM, region1, imageViewTitle, region2);
}
/*
Map<Integer, Map> kWh = DB.getKwh();
for (Map.Entry<Integer, Map> entryKwh : kWh.entrySet()) {
Map data = entryKwh.getValue();
XYChart.Series series = new XYChart.Series();
for (Object entryData : data.entrySet()){
//System.out.println("data: \t\t"+entryData);
String entryString = entryData.toString();
String[] arr = entryString.split("=");
String date = arr[0];
int kwhValue = Integer.parseInt(arr[1]);
//System.out.printf("Date: \t%s\t\t\tkWh: \t%s\n",date,kwhValue);
// Connect the data to a series
series.getData().add(new XYChart.Data(date,kwhValue));
}
lineChart.getData().add(series);
//System.out.println("\n\nNew line\n\n");
}
*/
/*
for (Map.Entry<Integer, Map> entryKwh : kWh.entrySet()) {
System.out.printf("Index: \t%s\t\t\tkWh: \t%s\n",entryKwh.getKey(),entryKwh.getValue());
}
*/
}
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment