JavaFX Line Chart

0

JavaFX Line Chart Tutorial:

  • JavaFx Line Chart is represented by two axis chart in which a series of datapoints connected with straight lines.
  • Line chart is mainly used to display trends over time.

Constructors :

  • LineChart(Axis xAxis, Axis yAxis)
    Construct a new LineChart with the given axis.
  • LineChart(Axis xAxis, Axis yAxis, ObservableList> data)
    Construct a new LineChart with the given axis and data.

Creating Line Chart :

  • First Create two axis for the line Chart using NumberAxis class.
  • Now creates an instance of LineChart using axis as
    LineChart lineChart = new LineChart(xAxis,yAxis);
  • Now create a series of data by using XYChart.Series Class as
    XYChart.Series dataSeries = new XYChart.Series();
  • Now assigning data for this series As
  • And at last add this series to the line Chart As
    lineChart.getData().add(dataSeries);

Example of line chart

Output :

Share.

Leave A Reply