JFXGraph code sample

G’Day.

In this post, I will demonstrate with code samples, just how a developer would use the JFXGraph application.

Note:
I have made a small update to the application that I posted about in the previous post, which will allow you to add your own bars to the graph, and, by double-clicking on a bar, will remove the bar from the graph.

Here is a screen shot of the current version (0.02) of the JFXGraph app:

As you can see, there is a small input control at the top left, and it has some small input validation, i.e. value must be a non-negative integer, etc…

The Code:
The code sample to get a basic graph with no columns is as shown below:

import javafx.scene.Scene;import javafx.stage.Stage;import jfxgraph.graphs.bar.BarGraph;

var graph = BarGraph {xPosition: 250,yPosition: 500,width: 400};

Stage {title: "JavaFX Graph"width: 800height: 600scene: Scene {   content: [graph];}}

This would render the following:

To add some columns, just do the following:

import javafx.scene.Scene;import javafx.stage.Stage;import jfxgraph.graphs.bar.BarGraph;import jfxgraph.graphs.bar.BarGraphColumn;

var graph = BarGraph {xPosition: 250,yPosition: 500,width: 400columns: [    BarGraphColumn{ tag: "Example1" value: 500 },    BarGraphColumn{ tag: "Example2" value: 300 },    BarGraphColumn{ tag: "Example3" value: 900 }]

};

Stage {title: "JavaFX Graph"width: 800height: 600scene: Scene {    content: [graph];}}

Which renders:

Pretty simple huh?

I love feedback, good and bad, so please if you have any comments or suggestions, please let me know.

Here is the JNLP link as usual:

3 Responses to "JFXGraph code sample"

  • MedSabri says:
  • Mark says:
  • Mark says:
Leave a Comment