无法在JavaFX LineChart中获得工具提示

时间:2018-06-26 10:25:32

标签: javafx linechart

我正在使用折线图,希望在其中单击鼠标时获得工具提示。 这是代码。请让我知道我写错了什么,以便无法获得工具提示。我也没有例外。

 public class ChartPlot  
 {
 static LineChart<Number,Number> linechart;
 static double[] xArray,yArray;
 static ArrayList<Double> xList,yList;
 public static  XYChart.Series series;
 public static XYChart.Data<Number, Number> data;

 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++) 
  {
      data = new XYChart.Data<>(xArray[i], yArray[i]);
        series.getData().add(data);           
  }

  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);

     linechart.setOnMouseEntered((MouseEvent event) -> {
         System.out.println("Clicked on Chart");
          Tooltip t = new Tooltip(data.getYValue().toString() + '\n' + data.getXValue().toString());
    Tooltip.install(data.getNode(), t);

    });

     return linechart;

    }
  }

我正在为线图使用setMouseOnClick()函数,还有其他方法可以做到吗?

预先感谢

0 个答案:

没有答案