Boa tarde, estou fazendo um aplicação onde utilizo o lineChart com JavaFx e FXML, aparentemente está tudo correto pois utilizei o mesmo conceito que quando fiz com BarChart, porém o não aparece valores no chart. Coloquei os valores manualmente, debuguei e vi que está chamando correto porém nada… Deve algo muito simples que não estou vendo, por isso estou pedindo ajuda.
FXML
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.chart.CategoryAxis?>
<?import javafx.scene.chart.LineChart?>
<?import javafx.scene.chart.NumberAxis?>
<?import javafx.scene.layout.AnchorPane?>
<AnchorPane prefHeight="450.0" prefWidth="620.0" xmlns="http://javafx.com/javafx/8.0.65" xmlns:fx="http://javafx.com/fxml/1" fx:controller="br.ind.risc.controller.ChartControllerLine">
<children>
<LineChart id="lineChart" layoutX="-6.0" prefHeight="450.0" prefWidth="620.0" title="Line Chart" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
<xAxis>
<CategoryAxis fx:id="xAxis" side="BOTTOM" />
</xAxis>
<yAxis>
<NumberAxis fx:id="yAxis" side="LEFT" />
</yAxis>
</LineChart>
</children>
</AnchorPane>
Controller
package br.ind.risc.controller;
import javafx.fxml.FXML;
import javafx.scene.chart.CategoryAxis;
import javafx.scene.chart.LineChart;
import javafx.scene.chart.NumberAxis;
import javafx.scene.chart.XYChart;
public class ChartControllerLine {
@FXML
private CategoryAxis xAxis = new CategoryAxis();
@FXML
private NumberAxis yAxis = new NumberAxis();
@FXML
private LineChart<String, Number> lineChart = new LineChart<>(xAxis, yAxis);
@FXML
private void initialize() {
xAxis.setLabel("BATATA");
}
@SuppressWarnings({ "rawtypes", "unchecked" })
public void generateChar() {
XYChart.Series series1 = new XYChart.Series<>();
series1.setName("My data");
series1.getData().add(new XYChart.Data("dfds", 123));
lineChart.getData().addAll(series1);
}
}
Chamada do controller
public void showTagsChartLine(LocalDate dt1, LocalDate dt2, int tag){
try {
FXMLLoader load = new FXMLLoader();
load.setLocation(ReportMain.class.getResource("../view/ChartsDataLine.fxml"));
AnchorPane pane = (AnchorPane) load.load();
Stage dialogStage = new Stage();
dialogStage.setTitle("Gráfico linha");
dialogStage.initModality(Modality.WINDOW_MODAL);
dialogStage.initOwner(primaryStage);
Scene scene = new Scene(pane);
dialogStage.setScene(scene);
ChartControllerLine controllerChart = load.getController();
controllerChart.generateChar();
dialogStage.setAlwaysOnTop(true);
dialogStage.setFullScreen(true);
dialogStage.show();
}catch(IOException e){
e.printStackTrace();
} catch (DAOException e) {
e.printStackTrace();
}
}
Grato pela ajuda.