在 JavaFX 中绘制数据集时,折线图不是自动调整大小

LineChart is not Auto Resize when the dataset is plot in JavaFX

我在 JavaFX 中使用折线图。我正在使用与输入长度相同的数组来绘制。 但是当我将它包含在我的应用程序中时,绘图不会自动调整大小。 我已经包含了快照的外观。

我想把线宽调小一点,也想改变颜色。

这是绘制此图的代码

public class ChartPlot extends Application {
    static LineChart<Number, Number> linechart;
    static double[] xArray, yArray;

    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<Number, Number>(xAxis, yAxis);

        // Prepare XYChart.Series objects by setting data
        XYChart.Series series = new XYChart.Series();
        // series.setName("No of schools in an year");

        // 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);
        return linechart;
    }
}

请帮我解决这个问题。

提前致谢

NumerAxis need to be added with autoRange. Here is the code
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<Number,Number>(xAxis,yAxis); 


  linechart.getData().clear();
  //Prepare XYChart.Series objects by setting data 
  XYChart.Series series = new XYChart.Series(); 
  //series.setName("No of schools in an year"); 

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

  *This is what I have Changed*

  **xAxis.setAutoRanging(true);
  xAxis.setForceZeroInRange(false);
  yAxis.setAutoRanging(true);
  yAxis.setForceZeroInRange(false);**
  linechart.autosize();
  linechart.applyCss();
    return linechart;

  }

}