我希望xAxis值从1到10.当我将xAxis lowerBound设置为'1'而不是'0'时,图表中的条形图正在消失。
NumberAxis xAxis = new NumberAxis();
xAxis.setAutoRanging(false);
xAxis.setLowerBound(1);
xAxis.setUpperBound(10);
xAxis.setTickUnit(1);
final CategoryAxis yAxis = new CategoryAxis();
final BarChart<Number,String> bc =new BarChart<Number,String>(xAxis,yAxis);
XYChart.Series series1 = new XYChart.Series();
series1.getData().add(new XYChart.Data(5, "XYZ"));
如何解决此问题?
答案 0 :(得分:0)
我刚试过这个,它对我有用。我正在使用java 8。
public class HorizBarChart extends Application {
@Override public void start(Stage stage) {
final NumberAxis xAxis = new NumberAxis();
xAxis.setAutoRanging(false);
xAxis.setLowerBound(1);
xAxis.setUpperBound(10);
xAxis.setTickUnit(1);
final CategoryAxis yAxis = new CategoryAxis();
final BarChart<Number,String> bc = new BarChart<>(xAxis,yAxis);
XYChart.Series series1 = new XYChart.Series();
series1.setName("1");
series1.getData().add(new XYChart.Data(5, "XYZ"));
series1.getData().add(new XYChart.Data(1, "ABC"));
series1.getData().add(new XYChart.Data(10, "def"));
Scene scene = new Scene(bc,800,600);
bc.getData().addAll(series1);
stage.setScene(scene);
stage.show();
}
}