2017-10-29 6 views
0

그래서 몇 줄의 모든 줄에서 문자를 읽는 응용 프로그램이 있고이 차트를 만들고 싶습니다. 차트는 괜찮아 보이지만 Im은 x 및 y 축의 숫자가 누락되었습니다. 차트가 HBox에 있거나 내가 만든 근처의 버튼에 있기 때문입니까? 실종JavaFX 캔트 X 및 Y 축 번호를 참조하십시오

내 애플과 번호 : 여기

public class Main extends Application { 

    @Override 
    public void start(Stage primaryStage) { 
     try { 
      HBox stack = new HBox(); 
      VBox buttons = new VBox(); 
      primaryStage.setTitle("Charts"); 

      final NumberAxis xAxis = new NumberAxis(); 
      final NumberAxis yAxis = new NumberAxis(); 
      xAxis.setLabel("Numer lini"); 
      yAxis.setLabel("Ilosc znakow"); 
      final LineChart<Number,Number> lineChart = new LineChart<Number,Number>(xAxis,yAxis); 
      final AreaChart<Number,Number> areaChart = new AreaChart<Number,Number>(xAxis,yAxis); 

      String f1 = "files/1.txt"; 
      String f2 = "files/2.txt"; 
      String f3 = "files/3.txt"; 

      XYChart.Series series = new XYChart.Series(); 
      XYChart.Series series2 = new XYChart.Series(); 
      XYChart.Series series3 = new XYChart.Series(); 

      series = createChart(f1); 
      series2 = createChart(f2); 
      series3 = createChart(f3); 

      Button b1 = new Button("B1"); 

      stack.getChildren().addAll(lineChart, b1); 
      lineChart.getData().addAll(series, series2, series3); 
      Scene scene = new Scene(stack, 800, 600); 




      primaryStage.setScene(scene); 
      primaryStage.show(); 

     } catch(Exception e) { 
      e.printStackTrace(); 
     } 
    } 


    private static XYChart.Series createChart(String fileName) throws FileNotFoundException{ 
     Reader r = new InputStreamReader(new FileInputStream(fileName)); 
     Scanner sc = new Scanner(r); 
     XYChart.Series series = new XYChart.Series(); 
     series.setName(fileName); 

     int chars = 0; 
     List<String> linie = new ArrayList<>(); 

     while(sc.hasNextLine()){ 
      linie.add(sc.nextLine().replaceAll(" ", "")); 
     } 
     for(int i = 0; i < linie.size(); i++){ 
      chars = linie.get(i).length(); 
      series.getData().add(new XYChart.Data(i, chars)); 
     } 
     sc.close(); 

     return series; 
    } 

    public static void main(String[] args) { 
     launch(args); 
    } 
} 

답변

0

와우 https://i.imgur.com/AXc3wvy.png

package application; 

/모든 수입! 투쟁 20 분 후, 나는 오류를 발견했습니다. LineCart와 AreaChart에 동일한 xAxis와 yAxis를 사용하고 있기 때문입니다. 단순히 xAxis 및 yAxis 객체가 아닌 다른 두 개의 NumberAxis를 사용하면 오류가 사라집니다. 그냥 줄을 주석

final AreaChart<Number,Number> areaChart = new AreaChart<Number,Number>(xAxis,yAxis); 

그리고 당신은 볼 것이다! 내가 말했듯이

은 간단하게,

+0

와우, 나는이이 문제를 일으킬 것으로 예상 didnt는 다른 차트에 대해 서로 다른 NumberAxis를 사용합니다. 고마워요. – murilo

+0

당신을 진심으로 환영합니다. 우스운 점은 오류를 잡기까지 어느 정도 시간이 걸렸습니다. 파일을로드 할 때 사이드 오류가 발생했습니다. –