i am doing an assignment which require me to plot a barchart in scalafx. The snippets below are the current code that i am writing. I have been thinking the error for 6 hours now.
var A : Int = 0
var B : Int = 0
var C : Int = 0
var D : Int = 0
var F : Int = 0
val xAxis : CategoryAxis = new CategoryAxis()
val yAxis : NumberAxis = new NumberAxis("Marks", 0.0d, 45.0d, 5.0d)
val barChart : BarChart[String, Int] = new BarChart[String, Int](xAxis, yAxis)
barChart.setTitle("Question Summary")
xAxis.setLabel("Category")
yAxis.setLabel("Number")
for(index <- 0 to questionDetails.length - 1){
if(questionDetails.apply(index).asInstanceOf[Double] < 40.0){
F += 1
}
if(questionDetails.apply(index).asInstanceOf[Double] < 50.0 &&
questionDetails.apply(index).asInstanceOf[Double] >= 40.0){
D += 1
}
if(questionDetails.apply(index).asInstanceOf[Double] < 60.0 &&
questionDetails.apply(index).asInstanceOf[Double] >= 50.0){
C += 1
}
if(questionDetails.apply(index).asInstanceOf[Double] < 70.0 &&
questionDetails.apply(index).asInstanceOf[Double] >= 60.0){
B += 1
}
if(questionDetails.apply(index).asInstanceOf[Double] >= 70.0){
A += 1
}
}
val series1 : XYChart.Series[String, Int] = new XYChart.Series()
val series2 : XYChart.Series[String, Int] = new XYChart.Series()
val series3 : XYChart.Series[String, Int] = new XYChart.Series()
val series4 : XYChart.Series[String, Int] = new XYChart.Series()
val series5 : XYChart.Series[String, Int] = new XYChart.Series()
val data1 : XYChart.Data[String, Int] = XYChart.Data(A.toString, A)
val data2 : XYChart.Data[String, Int] = XYChart.Data(B.toString, B)
val data3 : XYChart.Data[String, Int] = XYChart.Data(C.toString, C)
val data4 : XYChart.Data[String, Int] = XYChart.Data(D.toString, D)
val data5 : XYChart.Data[String, Int] = XYChart.Data(F.toString, F)
series1.getData().add(data1)
series2.getData().add(data2)
series3.getData().add(data3)
series4.getData().add(data4)
series5.getData().add(data5)
barChart.prefWidth = 300.0
barChart.getData().addAll(series1, series2, series3, series4, series5)
questionAnalysisPane.left = barChart
I got this error when i try to plot a graph to display data.
found : scalafx.scene.chart.NumberAxis
[error] required: scalafx.scene.chart.Axis[Int]
[error] val barChart : BarChart[String, Int] = new BarChart[String, Int]
(xAxis, yAxis)
How do i successfully plot a barchart in this situation? I am still a bit confused on this part. Your expertise and guidance is highly valuable. Thank you