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

started converting the x-axis to hours

parent 105b0b9e
No related branches found
No related tags found
No related merge requests found
package com.application.GUI;
import com.application.DB.DB;
import javafx.scene.chart.CategoryAxis;
import javafx.scene.chart.LineChart;
import javafx.scene.chart.NumberAxis;
import javafx.scene.chart.XYChart;
import javafx.scene.shape.Line;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Map;
public class LineChartFunctionality {
......@@ -42,6 +44,27 @@ public class LineChartFunctionality {
lineChart.getData().clear();
}
private static long findDifference(String start_date, String end_date) {
// Defining a simple date format
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
try{
// try to convert the string to Date datatype
Date dateStart = dateFormat.parse(start_date);
Date dateEnd = dateFormat.parse(end_date);
// Finds the difference in millis
long differenceMillis = dateEnd.getTime() - dateStart.getTime();
// Finds the difference in minutes
return (differenceMillis / (1000 * 60 )) % 60;
} catch (Exception e) {
System.out.println(e.getMessage());
}
return 0;
}
public static LineChart<String, Number> loadSingleSeries(Map<Integer, Map<String, Number>> userInput) throws Exception {
clearLineChart();
......@@ -54,20 +77,34 @@ public class LineChartFunctionality {
Map data = entryKwh.getValue();
//System.out.println(data.size());
XYChart.Series<String, Number> newSeries = new XYChart.Series<String, Number>();
int index = 0;
long minutes = 0;
long hours;
String previouseDate = "";
for (Object entryData : data.entrySet()) {
//System.out.println("data: \t"+entryData);
String entryString = entryData.toString();
String[] arr = entryString.split("=");
String date = arr[0];
String currentDate = arr[0];
int kwhValue = Integer.parseInt(arr[1]);
//System.out.printf("previouse date: \t%s\n",previouseDate);
//System.out.printf("Current date: \t\t%s\n",currentDate);
//System.out.printf("is prev empty?: \t%s\n",previouseDate.isEmpty());
minutes += findDifference(previouseDate, currentDate);
hours = (minutes/60);
System.out.println(hours);
previouseDate = currentDate;
//System.out.printf("Date: \t%s\t\t\tkWh: \t%s\n",date,kwhValue);
//System.out.printf("Hours: \t\t%s\n",hours);
// Connect the data to a series
newSeries.getData().add(new XYChart.Data<String, Number>(String.valueOf(index), kwhValue));
index += 1;
newSeries.getData().add(new XYChart.Data<String, Number>(String.valueOf(hours), kwhValue));
}
updateLineChart(newSeries);
}
......
......@@ -85,7 +85,7 @@ public class Main extends Application {
this.sideBar = createSideBar();
this.logoBar = createLogoBar();
LineChart<String, Number> lineChart = this.lineChartFunctionality.getLineChart();
LineChart<String, Number> lineChart = LineChartFunctionality.getLineChart();
//Set id's to connect to css stylesheet
root.setId("root");
......
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.
Finish editing this message first!
Please register or to comment