2016-11-05 7 views
1

私はlinecharグラフに問題があります。JavaFx Linechartレンダリングデータ

データがレンダリングされていない理由を私は理解していない:

package diagram; 

import Database.OracleConnector; 
import Hlavni.FXMLCMain; 
import atribute.DiagramAttribute; 
import java.net.URL; 
import java.sql.Connection; 
import java.sql.ResultSet; 
import java.sql.SQLException; 
import java.sql.Statement; 
import java.util.ResourceBundle; 
import java.util.logging.Level; 
import java.util.logging.Logger; 
import javafx.collections.FXCollections; 
import javafx.collections.ObservableList; 
import javafx.fxml.FXML; 
import javafx.fxml.Initializable; 
import javafx.scene.chart.LineChart; 
import javafx.scene.chart.NumberAxis; 
import javafx.scene.chart.XYChart; 

public class FXMLCdia implements Initializable { 

    strong textprivate FXMLCMain rootWindow; 

    @FXML 
    private LineChart<Number, Number> lineChart; 
    @FXML 
    private NumberAxis numberAxisx; 
    @FXML 
    private NumberAxis numberAxisy; 

    @Override 
    public void initialize(URL url, ResourceBundle rb) { 

     XYChart.Series series1 = new XYChart.Series(); 
     series1.setName("Portfolio 1"); 

     series1.getData().add(new XYChart.Data(7, 23)); 
     series1.getData().add(new XYChart.Data(8, 14)); 
     series1.getData().add(new XYChart.Data(9, 15)); 
     series1.getData().add(new XYChart.Data(10, 24)); 
     series1.getData().add(new XYChart.Data(11, 34)); 

     numberAxisx = new NumberAxis(); 
     numberAxisy = new NumberAxis(); 
     lineChart = new LineChart<Number, Number>(numberAxisx, numberAxisy); 
     lineChart.getData().addAll(series1); 
     System.out.println(lineChart.getData().get(0).getData()); 
     //result: [Data[7,23,null], Data[8,14,null], Data[9,15,null], Data[10,24,null],Data[11,34,null]] 
    } 

    public void setMainWindow(FXMLCMain rootWindow) { 
     this.rootWindow = rootWindow; 
    } 

FXMLファイル:

<?xml version="1.0" encoding="UTF-8"?> 

<?import javafx.scene.text.*?> 
<?import javafx.scene.chart.*?> 
<?import java.lang.*?> 
<?import java.net.*?> 
<?import java.util.*?> 
<?import javafx.scene.*?> 
<?import javafx.scene.control.*?> 
<?import javafx.scene.layout.*?> 

<AnchorPane id="AnchorPane" prefHeight="612.0" prefWidth="1352.0" styleClass="mainFxmlClass" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="diagram.FXMLCdia"> 
    <stylesheets> 
     <URL value="@fxmldia.css" /> 
    </stylesheets> 
    <children> 
     <LineChart fx:id="LineChart" layoutX="5.0" layoutY="5.0" prefHeight="605.0" prefWidth="1345.0" title="Production Oee"> 
     <xAxis> 
      <NumberAxis fx:id="numberAxisy" animated="false" autoRanging="false" label="Hour" minorTickCount="10" minorTickLength="10.0" prefHeight="55.0" prefWidth="1265.0" side="BOTTOM" tickLabelGap="1.0" tickLength="15.0" tickUnit="1.0" upperBound="23.0"> 
       <tickLabelFont> 
        <Font size="15.0" /> 
       </tickLabelFont></NumberAxis> 
     </xAxis> 
     <yAxis> 
      <NumberAxis fx:id="numberAxisx" animated="false" label="Percent" minorTickCount="10" minorTickLength="10.0" side="LEFT" tickLabelGap="10.0" tickLength="15.0" tickUnit="20.0"> 
       <tickLabelFont> 
        <Font size="15.0" /> 
       </tickLabelFont></NumberAxis> 
     </yAxis> 
     </LineChart> 
    </children> 
</AnchorPane> 

ここでは結果である:

enter image description here

答えて

1

これはチャートでありますFXMLファイルから。ここで

@FXML 
private LineChart<Number, Number> lineChart; 

....

あなたはそれが既にFXMLファイルで作られているように、新しいものを作る必要はありません新しいもの

lineChart = new LineChart<Number, Number>.. 

を作成します。 Axisでも同じことが起こります。

+0

これは多くの質問をしてからもう一度良い答えが見つかりました。 http://stackoverflow.com/a/29288214/2855515 – brian

+0

ありがとうございました。私はどのようにテーブルビューを非表示にするいくつかの解決策を見つけた。 – KozakSHR

関連する問題