-1
私はJavaFX APIを見て、私が働きたいと思う2つのグラフを得ました。私は彼らのお互いに好きですが、私は新しいので、これをどうやって行うのか分かりません。誰かがそれを助けることができたら、それは素晴らしいことでしょう! 、レイアウトペインのJavaFX(PieCharとXYGraphを使用するが、お互いに)
@Override public void start(Stage stage) {
// existing code, but remove this:
// Scene scene = new Scene(new Group());
// and replace this
// ((Group) scene.getRoot()).getChildren().add(bc);
// ((Group) scene.getRoot()).getChildren().add(chart);
// with this:
HBox root = new HBox();
root.getChildren().add(bc);
root.getChildren().add(chart);
Scene scene = new Scene(root);
stage.setScene(scene);
stage.show();
}
完全な説明など、HBox
tutorialである:あなたがお互いの横にそれらを必要とする場合
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.stage.Stage;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.scene.chart.*;
import javafx.scene.Group;
public class Main extends Application {
final static String housing = "Avg Housing Prices By Year";
final static String commercial = "AvgCommercialPrices By Year";
private static double[] avgHousingPricesByYear = {
247381.0, 264171.4, 287715.3, 294736.1, 308431.4, 322635.9, 340253.0, 363153.7
};
private static double[] avgCommercialPricesByYear = {
1121585.3, 1219479.5, 1246354.2, 1295364.8, 1335932.6, 1472362.0, 1583521.9, 1613246.3
};
private static String[] ageGroups = {
"18-25", "26-35", "36-45", "46-55", "56-65", "65+"
};
private static int[] purchasesByAgeGroup = {
648, 1021, 2453, 3173, 1868, 2247
};
@Override public void start(Stage stage) {
stage.setTitle("Lab06");
stage.setWidth(1000);
stage.setHeight(450);
final CategoryAxis xAxis = new CategoryAxis();
final NumberAxis yAxis = new NumberAxis();
final BarChart<String,Number> bc =
new BarChart<String,Number>(xAxis,yAxis);
bc.setTitle("Lab 06");
xAxis.setLabel("Housing");
yAxis.setLabel("Value");
XYChart.Series series1 = new XYChart.Series();
series1.setName(housing);
for(int i = 0 ; i < 8; i++){
series1.getData().add(new XYChart.Data(Integer.toString(2000 + i), avgHousingPricesByYear[i]));
}
XYChart.Series series2 = new XYChart.Series();
series2.setName(commercial);
for(int i = 0 ; i < 8; i++){
series2.getData().add(new XYChart.Data(Integer.toString(2000 + i), avgCommercialPricesByYear[i]));
}
Scene scene = new Scene(new Group());
bc.getData().addAll(series1, series2);
ObservableList<PieChart.Data> pieChartData =
FXCollections.observableArrayList();
for(int i = 0; i < 6; i++){
pieChartData.add(new PieChart.Data(ageGroups[i], purchasesByAgeGroup[i]));
}
final PieChart chart = new PieChart(pieChartData);
chart.setTitle("Purchases Example");
((Group) scene.getRoot()).getChildren().add(bc);
((Group) scene.getRoot()).getChildren().add(chart);
stage.setScene(scene);
stage.show();
}
public static void main(String[] args) {
launch(args);
}
}
ありがとうございました!それはまさに私が望んでいたものです。 – Nom