我对linechar图有问题。
我不明白,为什么不呈现数据:
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>
结果如下:
答案 0 :(得分:1)
这是FXML文件中的图表。
educational_institute
...
在这里创建一个新的
@FXML
private LineChart<Number, Number> lineChart;
您不必制作新的,因为它已在FXML文件中制作。 Axis也是如此。