0
public static XYChart.Series<Integer,Integer> makeSeries(ArrayList<Integer> date, ArrayList<Integer> cases) {

    XYChart.Series<Integer,Integer> series = new XYChart.Series<>();
    for(int i = 0; i < date.size();i++) {
        series.getData().add(new XYChart.Data<Integer,Integer>(date.get(i), cases.get(i))); 
    }
    return series;

}

public static LineChart<Number, Number> makeChart(ArrayList<XYChart.Series<Integer,Integer>> series) {
    NumberAxis xAxis = new NumberAxis(); 
    NumberAxis yAxis = new NumberAxis(); 
    LineChart<Number, Number> linechart = new LineChart<Number, Number>(xAxis, yAxis); 

    for(int i = 0; i < series.size();i++) {
        Series<Integer, Integer> num = series.get(i);
        linechart.getData().add(series.get(i));
    }
    return linechart;
}

So I have difficulty adding the data in the series to the line chart, it wouldn't let me use the add method.

The error message I got was:

The method add(XYChart.Series<Number,Number>) in the type List<XYChart.Series<Number,Number>> is not applicable for the arguments (XYChart.Series<Integer,Integer>)

I've also tried to type cast the series.get(i) into Number but it also doesn't seem to work...

Any help would be highly appreciated! Thank you!

Slaw
  • 37,820
  • 8
  • 53
  • 80
CSnewbie
  • 103
  • 1
  • 7
  • 2
    Since you have a `LineChart` you should be using `Series` and `Data`. You don't need to use `Integer` in any of the type arguments as it extends `Number`. – Slaw Apr 20 '20 at 04:03
  • @Slaw you're right but I don't understand why it raises an error instead of just ignoring it. – 0009laH Apr 20 '20 at 07:21
  • Check out [Is List a subclass of List? Why are Java generics not implicitly polymorphic?](https://stackoverflow.com/questions/2745265/). This is also somewhat related: [What is PECS (Producer Extends Consumer Super)?](https://stackoverflow.com/questions/2723397/). – Slaw Apr 20 '20 at 19:04
  • Thank you so much! – CSnewbie Apr 20 '20 at 22:30

0 Answers0