Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- package infs2605;
- import java.io.IOException;
- import java.net.URL;
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.ResultSet;
- import java.sql.SQLException;
- import java.sql.Statement;
- import java.util.ResourceBundle;
- import javafx.collections.FXCollections;
- import javafx.collections.ObservableList;
- import javafx.event.ActionEvent;
- import javafx.fxml.FXML;
- import javafx.fxml.Initializable;
- import javafx.scene.chart.BarChart;
- import javafx.scene.chart.CategoryAxis;
- import javafx.scene.chart.NumberAxis;
- import javafx.scene.chart.XYChart;
- import javafx.scene.control.Button;
- import javafx.scene.control.Label;
- /**
- *
- * @author I507088
- */
- public class DailyBreakdownController implements Initializable{
- @FXML
- private Button Home;
- PageSwitchHelper pageSwitcher = new PageSwitchHelper();
- @FXML
- private void goHomePage(ActionEvent event) throws IOException {
- pageSwitcher.switcher(event, "homePage.fxml");
- }
- @FXML
- private Label label;
- @FXML
- private Button btnLoad;
- @FXML
- private BarChart<String,Double> barChart;
- private Connection connect;
- private Connection connectDB() {
- try {
- String dbString="jdbc:sqlite:Database.db";
- Connection conn = DriverManager.getConnection(dbString);
- return conn;
- } catch (SQLException ex) {
- //Logger.getLogger(DailyBreakdownController.class.getName()).log(Level,SEVERE,null,ex);
- }
- return null;
- }
- @Override
- public void initialize(URL url, ResourceBundle rb) {
- }
- @FXML
- private void loadChart(ActionEvent event) {
- String query = "SELECT CATEGORY,DURATION FROM ENTRIES";
- XYChart.Series<String,Double> series = new XYChart.Series<>();
- try {
- connect=connectDB();
- ResultSet rs = connect.createStatement().executeQuery(query);
- while (rs.next()) {
- series.getData().add(new XYChart.Data<>(rs.getString(1),rs.getDouble(2)));
- }
- barChart.getData().add(series);
- } catch (Exception e){
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement