Guest User

Untitled

a guest
Jan 22nd, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.06 KB | None | 0 0
  1. @FXML
  2. private BarChart<String, Integer> barChart;
  3.  
  4. @FXML
  5. private CategoryAxis xAxis;
  6.  
  7. private ObservableList<String> dateA = FXCollections.observableArrayList();
  8.  
  9.  
  10. @FXML
  11. private void initialize() {
  12. // Get an array with the English month names.
  13. String[] months = DateFormatSymbols.getInstance(Locale.ENGLISH).getMonths();
  14. // Convert it to a list and add it to our ObservableList of months.
  15. dateA.addAll(Arrays.asList(months));
  16. // Assign the month names as categories for the horizontal axis.
  17. xAxis.setCategories(dateA);
  18. }
  19.  
  20.  
  21. /**
  22. *
  23. * @param entry
  24. */
  25. public void setEntryData(List<Entry> entry) {
  26. int[] monthCounter = new int[12];
  27. for (Entry p : entry) {
  28. int month = p.getDateA();
  29. monthCounter[month]++;
  30. }
  31.  
  32. XYChart.Series<String, Integer> series = new XYChart.Series<>();
  33.  
  34. // Create a XYChart.Data object for each month. Add it to the series.
  35. for (int i = 0; i < monthCounter.length; i++) {
  36. series.getData().add(new XYChart.Data<>(dateA.get(i), monthCounter[i]));
  37. }
  38.  
  39. barChart.getData().add(series);
  40.  
  41. }
Add Comment
Please, Sign In to add comment