XYChart.Series set=new XYChart.Series<>();
set.getData().add(new XYChart.Data<>("#Purchases",arrint.get(0)));
set.getData().add(new XYChart.Data<>("#Searches",arrint.get(1)));
mybar.getData().addAll(set);
我正在使用带有BarChart的javafx,我很清楚地看到了这些图表。问题是我看不到字符串'购买',而是显示搜索结果。
答案 0 :(得分:0)
对我来说很好。您可能需要更新Java JDK和JRE的版本。
public class JavaFXApplication9 extends Application {
final static String itemA = "#Purchases";//"A";
final static String itemB = "#Searches";//"B";
final static String itemC = "F";
@Override
public void start(Stage stage) {
final CategoryAxis xAxis = new CategoryAxis();
final NumberAxis yAxis = new NumberAxis();
final BarChart<String, Number> bc = new BarChart<String, Number>(xAxis, yAxis);
bc.setTitle("Summary");
xAxis.setLabel("Value");
xAxis.setTickLabelRotation(90);
yAxis.setLabel("Item");
XYChart.Series series1 = new XYChart.Series();
series1.setName("2003");
series1.getData().add(new XYChart.Data(itemA, 2));
series1.getData().add(new XYChart.Data(itemB, 20));
series1.getData().add(new XYChart.Data(itemC, 10));
// XYChart.Series series2 = new XYChart.Series();
// series2.setName("2004");
// series2.getData().add(new XYChart.Data(50, itemA));
// series2.getData().add(new XYChart.Data(41, itemB));
// series2.getData().add(new XYChart.Data(45, itemC));
//
// XYChart.Series series3 = new XYChart.Series();
// series3.setName("2005");
// series3.getData().add(new XYChart.Data(45, itemA));
// series3.getData().add(new XYChart.Data(44, itemB));
// series3.getData().add(new XYChart.Data(18, itemC));
// Timeline tl = new Timeline();
// tl.getKeyFrames().add(new KeyFrame(Duration.millis(500),
// new EventHandler<ActionEvent>() {
// @Override public void handle(ActionEvent actionEvent) {
// for (XYChart.Series<Number, String> series : bc.getData()) {
// for (XYChart.Data<Number, String> data : series.getData()) {
// data.setXValue(Math.random() * 100);
// }
// }
// }
// }));
// tl.setCycleCount(Animation.INDEFINITE);
// tl.play();
Scene scene = new Scene(bc, 800, 600);
bc.getData().add(series1);//.addAll(series1, series2, series3);
stage.setScene(scene);
stage.show();
}
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
launch(args);
}
}