2017-01-17 6 views
0
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を使用しています。私はグラフをよく見ています。問題は、検索が表示されている間、私は文字列 '購入'を見ることができないということです。BarChartはすべてのカテゴリを表示していません

答えて

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); 
    } 

} 

enter image description here

+0

、少なくとも答えを受け入れることによって回答が投資した時間に感謝してください、あなたにそのような場合には –

+1

素晴らしいので、多くの作品をありがとう。 – DVarga

関連する問題