【发布时间】:2017-12-19 08:37:28
【问题描述】:
我想通过 fxml 文件创建一个散点图。我将下面的代码放在我的 fxml 文件中,但是当它完成渲染时,它并不像我预期的那样。有人知道发生了什么吗?
<BorderPane xmlns="http://javafx.com/javafx/8.0.121"
xmlns:fx="http://javafx.com/fxml/1" fx:controller="sample.ChartController">
<left>
<ScatterChart fx:id="memoryDistribution" prefWidth="360" title="Memory Distribution">
<xAxis>
<NumberAxis fx:id="xAxis" label="Memory Address/k" lowerBound="0" upperBound="7" tickUnit="1.00"/>
</xAxis>
<yAxis>
<NumberAxis fx:id="yAxis" label="Memory Address/k" lowerBound="1" upperBound="257" tickUnit="8.00"/>
</yAxis>
</ScatterChart>
</left>
上面的代码是这样做的:
但我的期望是这样的:
expectation 第二张图片代码:
public class Main extends Application {
@Override
public void start(Stage primaryStage) throws Exception{
primaryStage.setTitle("Scatter Chart Sample");
final NumberAxis xAxis = new NumberAxis(0, 8, 1);
final NumberAxis yAxis = new NumberAxis(1, 257, 8);
final ScatterChart<Number,Number> sc = new
ScatterChart<>(xAxis,yAxis);
xAxis.setLabel("Memory Address/k");
yAxis.setLabel("Memory Address/k");
sc.setTitle("Memory Distribution");
XYChart.Series series1 = new XYChart.Series();
series1.setName("job-1");
series1.getData().add(new XYChart.Data(0.5, 5));
series1.getData().add(new XYChart.Data(1.5, 5));
series1.getData().add(new XYChart.Data(2.5, 5));
series1.getData().add(new XYChart.Data(3.5, 5));
series1.getData().add(new XYChart.Data(4.5, 5));
series1.getData().add(new XYChart.Data(5.5, 5));
series1.getData().add(new XYChart.Data(6.5, 5));
series1.getData().add(new XYChart.Data(7.5, 5));
series1.getData().add(new XYChart.Data(0.5, 13));
series1.getData().add(new XYChart.Data(1.5, 13));
series1.getData().add(new XYChart.Data(2.5, 13));
series1.getData().add(new XYChart.Data(3.5, 13));
series1.getData().add(new XYChart.Data(4.5, 13));
series1.getData().add(new XYChart.Data(5.5, 13));
XYChart.Series series2 = new XYChart.Series();
series2.setName("job-2");
series2.getData().add(new XYChart.Data(0.5, 29));
series2.getData().add(new XYChart.Data(1.5, 29));
series2.getData().add(new XYChart.Data(2.5, 29));
series2.getData().add(new XYChart.Data(3.5, 29));
series2.getData().add(new XYChart.Data(4.5, 29));
series2.getData().add(new XYChart.Data(5.5, 29));
sc.getData().addAll(series1, series2);
Scene chartScene = new Scene(sc,360,736);//best lookup
primaryStage.setScene(chartScene);
primaryStage.setMaximized(true);
primaryStage.show();
}
public static void main(String[] args) {
launch(args);
}
}
【问题讨论】:
-
您忘记在问题底部添加最后一段代码。
标签: javafx charts fxml scatter