Skip to content

Instantly share code, notes, and snippets.

@Sander-Voogt
Created April 18, 2016 08:43
Show Gist options
  • Save Sander-Voogt/13b30b9a445be4cd970bd6f7f153a075 to your computer and use it in GitHub Desktop.
Save Sander-Voogt/13b30b9a445be4cd970bd6f7f153a075 to your computer and use it in GitHub Desktop.
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.chart.BarChart;
import javafx.scene.chart.CategoryAxis;
import javafx.scene.chart.NumberAxis;
import javafx.scene.chart.XYChart;
import javafx.stage.Stage;
import java.sql.SQLException;
import java.util.ArrayList;
public class Query1 {
private Database db;
private ArrayList<NodeClass> query;
public Query1 (Database db2) throws SQLException {
db = db2;
String querry = "SELECT b.jaar, m.Totaal_wegvoertuigen / b.bevolking From motorvoertuigen_rotterdam m, bevolking b Where b.jaar = m.Jaar";
db.rs = db.stmt.executeQuery(querry);
query = new ArrayList<>();
while (db.rs.next()) {
query.add(new NodeClass("Jaar", db.rs.getInt("b.jaar")));
query.add(new NodeClass("Wegvoertuigen", db.rs.getInt("m.Totaal_wegvoertuigen / b.bevolking")));
}
};
public void display(){
Stage stage = new Stage();
stage.setTitle("Bar query Sample");
final CategoryAxis xAxis = new CategoryAxis();
final NumberAxis yAxis = new NumberAxis();
final BarChart<String, Number> bc =
new BarChart<String, Number>(xAxis, yAxis);
bc.setTitle("Soorten motorvoertuigen en hoeveelheid in 2015");
xAxis.setLabel("Motorvoertuigen");
yAxis.setLabel("Hoeveelheid");
XYChart.Series series1 = new XYChart.Series();
series1.setName("");
for (NodeClass values : query){
series1.getData().add(new XYChart.Data(values.naam,values.waarde));
}
Scene scene = new Scene(bc, 1920, 1080);
bc.getData().addAll(series1);
stage.setScene(scene);
stage.show();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment