javafx - javaFX Linechart 的工具提示中的错误
问题描述
我正在使用 JavaFX 线图。我正在尝试在折线图上设置工具提示。我在事件句柄中收到错误运行时错误。代码有什么问题?
public class ChartPlot
{
static LineChart <Number,Number> linechart;
static double[] xArray, yArray;
static ArrayList <Double> xList, yList;
public static XYChart.Series series;
public static LineChart linePlot(double[] x, double[] y) {
xArray = new double[x.length];
yArray = new double[y.length];
xArray = x;
yArray = y;
//Defining the x axis
final NumberAxis xAxis = new NumberAxis();
xAxis.setLabel("Wavelength");
//Defining the y axis
final NumberAxis yAxis = new NumberAxis();
yAxis.setLabel("Intensity");
//Creating the line chart
linechart = new LineChart <>(xAxis, yAxis);
linechart.getData().clear();
//Prepare XYChart.Series objects by setting data
series = new XYChart.Series();
//Setting the data to Line chart
for (int i = 0; i < xArray.length; i++) {
series.getData().add(new XYChart.Data(xArray[i], yArray[i]));
}
linechart.setCreateSymbols(false);
linechart.getData().add(series);
xAxis.setAutoRanging(true);
xAxis.setForceZeroInRange(false);
yAxis.setAutoRanging(true);
yAxis.setForceZeroInRange(false);
linechart.autosize();
linechart.applyCss();
String css = FXMLDocumentController.class.getResource("LSG.css").toExternalForm();
linechart.getStylesheets().add(css);
linechart.setLegendVisible(false);
for (XYChart.Series <Number, Number> s: linechart.getData()) {
for (XYChart.Data <Number, Number> d: s.getData()) {
Tooltip.install(d.getNode(), new Tooltip(
d.getXValue().toString() + "," + d.getYValue()));
//Adding Class on Hover or on click
d.getNode().addEventHandler(MouseEvent.MOUSE_CLICKED, new EventHandler < MouseEvent > () //----- This is the line I am getting error
{@Override
public void handle(MouseEvent event) {
System.out.println("X :" + d.getXValue() + " Y :" + d.getYValue());
}
});
}
}
return linechart;
}
}
我正在使用打开按钮来读取文件和绘图。在绘图时,我试图插入侦听器以显示我单击的值。
解决方案
推荐阅读
- javascript - 是否可以在给 javascript 正则表达式中的前瞻表达式的模式中使用捕获组?
- sql - SQL Count Where on a specific date...但结果为 0
- python-3.x - 从excel vba中调用python脚本的问题
- javascript - 更改规则时,Firebase 数据库权限被拒绝
- angular - 带有固定拇指标签的 Angular Material mat-slider
- excel - 如何从 PowerPivot 数据模型中引入与一个月的最后一天相关的 Excel 的简单单元格?
- flutter - 如何:将颤振屏幕从一个颤振应用程序添加到另一个颤振应用程序?
- java - 关于 String.charAt(); 的问题 在爪哇
- node.js - IBM Cloud Functions 在 Watson Assistant / node.js / json 中打印 API 响应
- java - OWLAPI 在子类断言上设置 DataProperty 严格值