【发布时间】:2019-07-27 09:38:42
【问题描述】:
我正在创建一个新的窗口控制器,我在其中处理要放入折线图中的数据。
虽然最后新窗口显示了一个空的 LineChart。当我调试将系列放入折线图中的行时,IDE 状态为“series[null]”。
那么我错过了什么?
新窗口的类:
公共类图表窗口{
Map<Job, List<LoadTestResultStatus>> lTRSMapOfJobs;
final LineChart lineChartMain;
Job originJob;
XYChart.Series series;
boolean lTRSfilled=false;
ObjectHub objectHub;
public ChartWindow(Job job, ObjectHub objectHub) {
this.objectHub = objectHub;
series = new XYChart.Series();
final NumberAxis xAxis = new NumberAxis();
final NumberAxis yAxis = new NumberAxis();
xAxis.setLabel("Time");
yAxis.setLabel("Time");
lineChartMain = new LineChart<Number, Number>(xAxis, yAxis);
lTRSMapOfJobs = new HashMap<>();
originJob = job;
lTRSMapOfJobs.put(job, objectHub.getDbManagement().getLTRSListOfJobFromDB(job));
fillLineChart();
}
public void fillLineChart() {
Platform.runLater(new Runnable() {
@Override
public void run() {
objectHub.getGuiReporter().statusStart(0);
objectHub.getGuiReporter().progressbarAddAmountOfStep(lTRSMapOfJobs.get(originJob).size());
}
});
for (LoadTestResultStatus l : lTRSMapOfJobs.get(originJob)) {
objectHub.getExecutor().submit(new Runnable() {
@Override
public void run() {
XYChart.Data xyChart = new XYChart.Data(l.getTs(), l.getLt());
try {
addToSeries(xyChart);
objectHub.getGuiReporter().progressbarAddStep();
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
//TODO heavy CPU load:(
while(!lTRSfilled){
if(ObjectHub.getGuiReporter().progressBarDifference()==0){
lTRSfilled = true;
}
}
lineChartMain.getData().addAll(series);
}
void addToSeries(XYChart.Data xyChart) {
synchronized (this) {
series.getData().add(xyChart);
}
}
public Map<Job, List<LoadTestResultStatus>> getlTRSMapOfJobs() {
return lTRSMapOfJobs;
}
public void setlTRSMapOfJobs(Map<Job, List<LoadTestResultStatus>> lTRSMapOfJobs) {
this.lTRSMapOfJobs = lTRSMapOfJobs;
}
public LineChart getLineChartMain() {
return lineChartMain;
}
}
处理新窗口的MainController方法:
public void showLineChartForJob() {
progressBarLabel.setText("Preparing Linechart calculation...");
ChartWindow object to request executorservices
Thread createChartWindow = new Thread(new Runnable() {
@Override
public void run() {
int jobId = Integer.parseInt(visualizeTabIdInputTextField.getText());
Job lineChartJob = new Job(objectHub);
for (Job j : objectHub.getLtResultManagement().getjobSet()) {
if (j.getNumber() == jobId) {
lineChartJob = j;
break;
}
}
chartWindowList.add(new ChartWindow(lineChartJob, objectHub));
Platform.runLater(new Runnable() {
@Override
public void run() {
FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("/fxml/ChartWindow.fxml"));
fxmlLoader.setController(chartWindowList.get(0));
StackPane secondaryLayout = new StackPane();
try {
secondaryLayout.getChildren().setAll(Collections.singleton(fxmlLoader.load()));
} catch (IOException e) {
e.printStackTrace();
}
Scene secondScene = new Scene(secondaryLayout, 1200, 1600);
Stage newWindow = new Stage();
newWindow.setTitle("Second Stage");
newWindow.setScene(secondScene);
newWindow.setX(50);
newWindow.setY(50);
newWindow.show();
}
});
}
});
createChartWindow.setName("createChartWindowThread");
createChartWindow.start();
}
问候
【问题讨论】:
-
Series#toString()返回"Series[" + getName() + "]"。如果没有设置名称,您最终会得到Series[null]。你问的是这个吗? -
不完全是,出于绝望,我假设该系列中的一个关键领域可能没有启动。这也是一个非常有用的评论。谢谢!
标签: javafx null series linechart