Line Chart Using JAVAFX

In this example we are seeing how to develop Line Chart application using technologies JavaFX.

A line chart or line graph displays information as a series of data points (markers) connected by straight line segments. A Line Chart shows how the data changes at equal time frequency.

In JavaFX, a line chart is represented by a class named LineChart. This class belongs to the package javafx.scene.chart. By instantiating this class, you can create a LineChart node in JavaFX.

<?xml version="1.0" encoding="UTF-8"?>

<?import javafx.scene.chart.CategoryAxis?>
<?import javafx.scene.chart.LineChart?>
<?import javafx.scene.chart.NumberAxis?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.layout.AnchorPane?>

<AnchorPane prefHeight="500.0" prefWidth="500.0" xmlns:fx="" xmlns="" fx:controller="application.LineController">
      <LineChart fx:id="lineChart" title="LINE CHART">
          <CategoryAxis label="Month" side="BOTTOM" />
          <NumberAxis label="Salary" side="LEFT" />
      <Button layoutX="198.0" layoutY="419.0" mnemonicParsing="false" onAction="#generateLineChart" prefHeight="48.0" prefWidth="125.0" text="Generate Line Chart" />
package application;

import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.scene.chart.LineChart;
import javafx.scene.chart.XYChart;

public class LineController {
	LineChart<String,Number> lineChart;
	public void generateLineChart(ActionEvent ae){
		XYChart.Series<String,Number> series=new XYChart.Series<String,Number>();
		series.getData().add(new XYChart.Data<String, Number>("Jan",200));
		series.getData().add(new XYChart.Data<String, Number>("Feb",100));
		series.getData().add(new XYChart.Data<String, Number>("Mar",300));
		series.getData().add(new XYChart.Data<String, Number>("Apr",400));
		series.setName("Month Pay");
package application;
import javafx.application.Application;

import javafx.fxml.FXMLLoader;
import javafx.stage.Stage;
import javafx.scene.Parent;
import javafx.scene.Scene;

public class Main extends Application {
	public void start(Stage primaryStage) {
		try {
			Parent root=FXMLLoader.load(getClass().getResource("/application/Line.fxml"));
			Scene scene = new Scene(root);
		} catch(Exception e) {
	public static void main(String[] args) {

Contact Us

Tel: (+91) 0120  4118730  

Time :   10 : 00  AM -  08 : 00 PM IST 

Registered address: G-69, Sector 63, 

 Noida - 201301, India

We Provide Services Across The different countries

USA    Australia   Canada   UK    UAE    Singapore   New Zealand    Malasia   India   Ireland   Germany

Terms and Conditions        Privacy Policy    Pricing Policy       Refund Policy         COPYRIGHT © 2021

Sofstack Technology Solutions Pvt. Ltd.

  • CodersArts | Linkedin
  • Instagram