我在JavaFX项目中有一个自定义的LineChartWithMarkers控件。
我在Java(FX)编程中暂停了两年,发现Java 10中不再存在LineChartBuilder。
我能找到一些文档说它在版本8中已被弃用,但没有找到如何替换它。
如何修复代码以使用Java 10?
这就是我所拥有的:
public class LineChartWithMarkersBuilder extends LineChartBuilder {
private Axis<Number> xAxis ;
private Axis<Number> yAxis ;
private ObservableList<Series<Number,Number>> data ;
public static LineChartWithMarkersBuilder create() {
return new LineChartWithMarkersBuilder();
}
public LineChartWithMarkersBuilder xAxis(Axis<Number> xAxis) {
this.xAxis = xAxis ;
return this ;
}
public LineChartWithMarkersBuilder yAxis(Axis<Number> yAxis) {
this.yAxis = yAxis ;
return this ;
}
public LineChartWithMarkers<Number, Number> build() {
xAxis = new NumberAxis();
yAxis = new NumberAxis();
return new LineChartWithMarkers<Number, Number>( xAxis, yAxis);
}
}
以及带有标记的自定义折线图:
public class LineChartWithMarkers<X extends Number, Y extends Number> extends LineChart<X, Y> {
private ObservableList<Data<Number, Number>> verticalMarkers;
public LineChartWithMarkers(Axis<X> xAxis, Axis<Y> yAxis) {
super(xAxis, yAxis);
this.setCreateSymbols(false);
verticalMarkers = FXCollections.observableArrayList(data -> new Observable[] {data.XValueProperty()});
verticalMarkers.addListener((InvalidationListener)observable -> layoutPlotChildren());
}
(...)
}
我用的是。fxml如下:
...
<LineChartWithMarkers fx:id="chartFit" createSymbols="false" layoutX="14.0" layoutY="54.0" prefHeight="499.0" prefWidth="987.0" AnchorPane.bottomAnchor="162.0" AnchorPane.leftAnchor="14.0" AnchorPane.rightAnchor="5.0" AnchorPane.topAnchor="54.0">
<xAxis>
<NumberAxis side="BOTTOM" />
</xAxis>
<yAxis>
<NumberAxis side="LEFT" />
</yAxis>
</LineChartWithMarkers>
...