JavaFx DateAxis(Kenya 2011 Road Accidents)

                     JAVAFX    DATEAXIS/SCATTERCHART    

Again  openkenyadata  has the data of 2011 road incidents link (only),don't understand why cause Kenya has the highest road accidents in Africa, and only one year data set published.

JavaFx doesn't have a dateAxis which lets you set Date as value on a XYChart,thanks their is a library for that ExtFX which has other controls i.e NumberSpinner.

Example of how to use  DateAxis

ObservableList<XYChart.Series<Date, Number>> series = FXCollections.observableArrayList();
ObservableList<XYChart.Data<Date, Number>> series1Data = FXCollections.observableArrayList();
//add data to the series
 series1Data.add(new XYChart.Data<>(Date,Number));
 series1Data.add(new XYChart.Data<>(Date,Number));

 series.add(new XYChart.Series<>("Series1", series1Data));

 NumberAxis numberAxis = new NumberAxis(-1,25,1);
 numberAxis.setLabel("Deaths");

DateAxis dateAxis = new DateAxis();
dateAxis.setLabel("Year 2011");

ScatterChart<Date, Number> scatterChart = new ScatterChart<>(dateAxis, numberAxis, series);
scatterChart .setTitle("2011 Road Accidents");

The data is in csv format(comma separated value file),which has time of accidents records,number of deaths,injured and causes and more but we are interested with the mentioned ones.
Accidents recorded total of 1354.

Reading the File

 Scanner  sc=new Scanner(new BufferedReader(new FileReader("acc.csv")));

String line;

 while(sc.hasNextLine()){

          line=sc.nextLine();

         String rry[]=line.split(",");

         int death=Integer.parseInt(rry[8]);//at column 8 death records
}
SampleData

The results

Death Chart


Injuries


Negligence Vs Error








Comments

Popular Posts