Skip to content

Instantly share code, notes, and snippets.

@TheItachiUchiha
Created April 14, 2015 14:31
Show Gist options
  • Save TheItachiUchiha/cd6ad13a111c7a677f73 to your computer and use it in GitHub Desktop.
Save TheItachiUchiha/cd6ad13a111c7a677f73 to your computer and use it in GitHub Desktop.
package sample;
import javafx.collections.FXCollections;
import javafx.collections.ListChangeListener;
import javafx.collections.ObservableList;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.chart.CategoryAxis;
import javafx.scene.chart.NumberAxis;
import javafx.scene.chart.StackedBarChart;
import javafx.scene.chart.XYChart;
import javafx.scene.control.ScrollPane;
import javafx.scene.control.SplitPane;
import javafx.scene.control.TableView;
import javafx.scene.layout.AnchorPane;
import java.net.URL;
import java.util.ResourceBundle;
public class Controller implements Initializable{
@FXML
private AnchorPane anchorPane;
@FXML
private ScrollPane scrollPane;
@FXML
private SplitPane splitPane;
@FXML
private StackedBarChart<String, Number> stackedBarChart;
@FXML
private TableView<String> tableView;
@FXML
private CategoryAxis categoryAxis;
@FXML
private NumberAxis numberAxis;
private ObservableList<String> tableList;
private ObservableList<Integer> chartValueList = FXCollections.observableArrayList();
public void setTableList(ObservableList<String> tableList) {
this.tableList = FXCollections.observableList(tableList);
}
public void setChartValueList(ObservableList<Integer> chartValueList) {
this.chartValueList = FXCollections.observableList(chartValueList);
}
@Override
public void initialize(URL location, ResourceBundle resources) {
}
public void setChart(){
XYChart.Series<String,Number> series1 = new XYChart.Series();
series1.getData().add(new XYChart.Data("January", chartValueList.get(0)));
series1.getData().add(new XYChart.Data("February", chartValueList.get(1)));
series1.getData().add(new XYChart.Data("March", chartValueList.get(2)));
series1.getData().add(new XYChart.Data("April", chartValueList.get(3)));
XYChart.Series<String,Number> series2 = new XYChart.Series();
series2.getData().add(new XYChart.Data("January", chartValueList.get(0)));
series2.getData().add(new XYChart.Data("February", chartValueList.get(1)));
series2.getData().add(new XYChart.Data("March", chartValueList.get(2)));
series2.getData().add(new XYChart.Data("April", chartValueList.get(3)));
stackedBarChart.getData().addAll(series1, series2);
}
}
package sample;
import javafx.application.Application;
import javafx.beans.binding.Bindings;
import javafx.beans.property.DoubleProperty;
import javafx.beans.property.SimpleDoubleProperty;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.concurrent.Task;
import javafx.event.EventHandler;
import javafx.fxml.FXMLLoader;
import javafx.scene.Group;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.scene.input.DragEvent;
import javafx.scene.input.MouseEvent;
import javafx.stage.Screen;
import javafx.stage.Stage;
import javafx.util.StringConverter;
import javafx.util.converter.NumberStringConverter;
import javafx.util.converter.ShortStringConverter;
import java.text.DecimalFormat;
import java.text.NumberFormat;
import java.text.ParseException;
import java.util.Currency;
import java.util.Locale;
import java.util.Random;
import java.util.stream.IntStream;
public class Main extends Application {
private final int NUMBER_OF_COPIES = 5;
private final int NUMBER_OF_ROWS = 10;
private ObservableList<String> tableList = FXCollections.observableArrayList();
private ObservableList<Integer> chartValueList = FXCollections.observableArrayList();
@Override
public void start(Stage primaryStage) throws Exception{
for(int i=0; i<NUMBER_OF_COPIES; i++) {
FXMLLoader loader = new FXMLLoader(getClass().getResource("/split.fxml"));
Parent parent = loader.load();
Controller controller = loader.getController();
fillChartValueList();
controller.setChartValueList(chartValueList);
controller.setChart();
Scene scene = new Scene(parent, 600, 600);
Stage stage = new Stage();
stage.setScene(scene);
//stage.setX(Screen.getPrimary().getBounds().getMaxX());
stage.show();
};
}
public static void main(String[] args) {
launch(args);
}
private void fillChartValueList(){
// clear previous values
chartValueList.clear();
Random rand = new Random();
int min = 1000;
int max = 8000;
for(int i=0; i<NUMBER_OF_ROWS; i++) {
int randomNum = rand.nextInt((max - min) + 1) + min;
chartValueList.add(randomNum);
}
}
}
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.chart.*?>
<?import javafx.scene.image.*?>
<?import javafx.scene.text.*?>
<?import java.lang.*?>
<?import java.util.*?>
<?import javafx.scene.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<AnchorPane fx:id="anchorPane" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="365.0" prefWidth="767.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="sample.Controller">
<children>
<ScrollPane fx:id="scrollPane" prefHeight="364.0" prefWidth="778.0">
<content>
<FlowPane prefHeight="353.0" prefWidth="745.0">
<children>
<SplitPane fx:id="splitPane" dividerPositions="0.25" prefHeight="363.0" prefWidth="773.0">
<items>
<TableView fx:id="tableView" prefHeight="458.0" prefWidth="251.0">
<columns>
<TableColumn prefWidth="75.0" text="C1" />
<TableColumn prefWidth="75.0" text="C2" />
</columns>
</TableView>
<StackedBarChart fx:id="stackedBarChart" prefHeight="210.0" prefWidth="107.0">
<xAxis>
<CategoryAxis fx:id="categoryAxis" side="BOTTOM" label="Year" />
</xAxis>
<yAxis>
<NumberAxis fx:id="numberAxis" side="LEFT" label="Value"/>
</yAxis>
</StackedBarChart>
</items>
</SplitPane>
</children>
</FlowPane>
</content>
</ScrollPane>
</children>
</AnchorPane>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment