Advertisement
Guest User

Untitled

a guest
Nov 15th, 2019
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.65 KB | None | 0 0
  1. /*
  2. * To change this license header, choose License Headers in Project Properties.
  3. * To change this template file, choose Tools | Templates
  4. * and open the template in the editor.
  5. */
  6. package infs2605;
  7.  
  8. import java.io.IOException;
  9. import java.net.URL;
  10. import java.sql.Connection;
  11. import java.sql.DriverManager;
  12. import java.sql.ResultSet;
  13. import java.sql.SQLException;
  14. import java.sql.Statement;
  15. import java.util.ResourceBundle;
  16. import javafx.collections.FXCollections;
  17. import javafx.collections.ObservableList;
  18. import javafx.event.ActionEvent;
  19. import javafx.fxml.FXML;
  20. import javafx.fxml.Initializable;
  21. import javafx.scene.chart.BarChart;
  22. import javafx.scene.chart.CategoryAxis;
  23. import javafx.scene.chart.NumberAxis;
  24. import javafx.scene.chart.XYChart;
  25. import javafx.scene.control.Button;
  26. import javafx.scene.control.Label;
  27.  
  28. /**
  29. *
  30. * @author I507088
  31. */
  32. public class DailyBreakdownController implements Initializable{
  33.  
  34. @FXML
  35. private Button Home;
  36.  
  37. PageSwitchHelper pageSwitcher = new PageSwitchHelper();
  38.  
  39. @FXML
  40. private void goHomePage(ActionEvent event) throws IOException {
  41. pageSwitcher.switcher(event, "homePage.fxml");
  42. }
  43.  
  44.  
  45.  
  46.  
  47. @FXML
  48. private Label label;
  49.  
  50. @FXML
  51. private Button btnLoad;
  52.  
  53. @FXML
  54. private BarChart<String,Double> barChart;
  55.  
  56. private Connection connect;
  57.  
  58.  
  59. private Connection connectDB() {
  60. try {
  61. String dbString="jdbc:sqlite:Database.db";
  62.  
  63. Connection conn = DriverManager.getConnection(dbString);
  64. return conn;
  65. } catch (SQLException ex) {
  66. //Logger.getLogger(DailyBreakdownController.class.getName()).log(Level,SEVERE,null,ex);
  67.  
  68. }
  69.  
  70. return null;
  71. }
  72.  
  73.  
  74.  
  75. @Override
  76. public void initialize(URL url, ResourceBundle rb) {
  77.  
  78. }
  79.  
  80. @FXML
  81. private void loadChart(ActionEvent event) {
  82. String query = "SELECT CATEGORY,DURATION FROM ENTRIES";
  83. XYChart.Series<String,Double> series = new XYChart.Series<>();
  84. try {
  85. connect=connectDB();
  86. ResultSet rs = connect.createStatement().executeQuery(query);
  87. while (rs.next()) {
  88. series.getData().add(new XYChart.Data<>(rs.getString(1),rs.getDouble(2)));
  89.  
  90. }
  91. barChart.getData().add(series);
  92.  
  93. } catch (Exception e){
  94. }
  95. }
  96. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement