Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9012693
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T03:04:14+00:00 2026-06-16T03:04:14+00:00

I am new to Java and so to JavaFX. I am trying to build

  • 0

I am new to Java and so to JavaFX. I am trying to build a dynamic graph which displays live data using JavaFx LineChart. I am using NumberAxis to set values for my X-Axis. I tried using both the constructors of NumberAxis and noticed that it automatically sets the X-Axis values as 1,2,3,4..etc.

But I want to display values in a different order like 1,3,4,5,2… and not in ascending order. Could someone please guide me in this regard ? Any help is very much appreciated. Thanks !

Here is how my code looks,

public class UI extends Application{

@SuppressWarnings("unchecked")
public static XYChart.Series series = new XYChart.Series();
public static XYChart.Series series1 = new XYChart.Series();


/**
 * @param args
 */ 


public static void main(String[] args) {        
    launch(args);
}

@Override 
public void start(Stage primaryStage) throws Exception {
    BorderPane border = new BorderPane();
    //HBox hbox = addHBox();
    border.setTop(addHBox());
    border.setCenter(addLineChart());

    Scene scene = new Scene(border);

    primaryStage.setScene(scene);
    primaryStage.setHeight(570);
    primaryStage.setWidth(700);
    //primaryStage.setResizable(false);
    primaryStage.centerOnScreen();


    //primaryStage.setFullScreen(true);


    primaryStage.show();
}

public HBox addHBox() {
    HBox hbox = new HBox();
    hbox.setStyle("-fx-background-color: #e6e6fa;");//d3d3d3 gray, f5f5f5 smoke white


    hbox.setPadding(new Insets(0, 0, 0, 560));
    hbox.setSpacing(10);

    hbox.setMaxWidth(10);
    hbox.setStyle("-fx-background-color: #e6e6fa;");//d3d3d3 gray, f5f5f5 smoke white

    //Label logoLabel = new Label();
    Image logoImage = new Image(getClass().getResourceAsStream("Logo.jpeg"));       
    ImageView logoImageViewer = new ImageView();        
    //Rectangle2D viewportRect = new Rectangle2D(40, 35, 110, 110);
    //logoImageViewer.setViewport(viewportRect);

    logoImageViewer.setImage(logoImage);        
    logoImageViewer.setPreserveRatio(true);
    logoImageViewer.setSmooth(true);
    logoImageViewer.setCache(true);

    hbox.getChildren().add(logoImageViewer);
    return hbox;
}



public Node addLineChart(){

    //final NumberAxis xAxis = new NumberAxis(1,10,1);      
    final CategoryAxis xAxis = new CategoryAxis();

    xAxis.setAutoRanging(false);


    final NumberAxis yAxis = new NumberAxis(-80,60,20);        
    yAxis.setMinorTickVisible(false);




    final LineChart<String,Number> lineChart = new LineChart<String,Number>(xAxis,yAxis);




    //populating the series with data
    series.getData().add(new XYChart.Data("1", 20.222222222));//Math.random()));
    series.getData().add(new XYChart.Data("3", 0));//Math.random()));
    series.getData().add(new XYChart.Data("4", 1));//Math.random()));
    series.getData().add(new XYChart.Data("2", -60.11111));//Math.random()));

    lineChart.getData().add(series);
    lineChart.setLegendVisible(false);

    return lineChart;
}

}

Exception seen on using CategoryAxis,

Exception in Application start method
Exception in thread "main" java.lang.RuntimeException: Exception in Application start    method
     at com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:403)
     at com.sun.javafx.application.LauncherImpl.access$000(LauncherImpl.java:47)
     at com.sun.javafx.application.LauncherImpl$1.run(LauncherImpl.java:115)
     at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.NullPointerException
    at javafx.scene.chart.Axis.layoutChildren(Axis.java:634)
    at javafx.scene.Parent.layout(Parent.java:1018)
    at javafx.scene.chart.XYChart.layoutChartChildren(XYChart.java:684)
    at javafx.scene.chart.Chart$1.layoutChildren(Chart.java:84)
    at javafx.scene.Parent.layout(Parent.java:1018)
    at javafx.scene.Scene.layoutDirtyRoots(Scene.java:513)
    at javafx.scene.Scene.doLayoutPass(Scene.java:484)
    at javafx.scene.Scene.preferredSize(Scene.java:1485)
    at javafx.scene.Scene.impl_preferredSize(Scene.java:1512)
    at javafx.stage.Window$10.invalidated(Window.java:719)
    at javafx.beans.property.BooleanPropertyBase.markInvalid(BooleanPropertyBase.java:127)
    at javafx.beans.property.BooleanPropertyBase.set(BooleanPropertyBase.java:161)
    at javafx.stage.Window.setShowing(Window.java:782)
    at javafx.stage.Window.show(Window.java:797)
    at javafx.stage.Stage.show(Stage.java:229)
    at com.bosch.mvci.ford.powerbalance.ui.UI.start(UI.java:184)
    at com.sun.javafx.application.LauncherImpl$5.run(LauncherImpl.java:319)
    at com.sun.javafx.application.PlatformImpl$5.run(PlatformImpl.java:206)
    at com.sun.javafx.application.PlatformImpl$4.run(PlatformImpl.java:173)
    at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
    at com.sun.glass.ui.win.WinApplication.access$100(WinApplication.java:29)
    at com.sun.glass.ui.win.WinApplication$3$1.run(WinApplication.java:73)
... 1 more`
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T03:04:15+00:00Added an answer on June 16, 2026 at 3:04 am

    Use a CategoryAxis for your x axis.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to build a java project using Netbeans IDE 7.1. I somehow
I am trying to build registration system with java servlet. And insert data into
I am trying to build a java applet which downloads a file to the
I am trying to build a simple app using google app engine, with java
I am trying to create a new Java EE project using hibernate and JPA
I am trying a very simple use of JavaFX using a simple set of
I'm trying to build my first fractal (Pythagoras Tree): alt text http://img13.imageshack.us/img13/926/lab6e.jpg in Java
Being completely new to Java EE (but not to Java itself) I'm trying to
I am new to spring. I am trying to use spring mvc to build
I'm trying to create a new annotation with which I'll do some runtime wiring,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.