How to use ChartDirector.XYChart addLineLayer() method with argument as Double;

334 views Asked by At

I want to display my output in graphical format using ChartDirector.XYChart.When I use its addLineLayer()method with arugument as Double Type array, then it shows an error "The method addLineLayer(double[]) in the type XYChart is not applicable for the arguments (Double[])".but When I use double as argument then it takes the value.The values in Double Array holds the LinkedHashMap value. So it cant't be represented in primitive type double array. My code is:

            //Assign linkedHashMap values to array  
Double[] avg=  (Double[]) averageMap.values().toArray();
char[] time= rs.getString(logtime).toCharArray();
XYChart c = new XYChart(250, 250);
c.setPlotArea(30, 20, 200, 200);
c.addLineLayer(avg);

Error is on c.addlineLayer.How to fix it.

thanks in advance.

1

There are 1 answers

0
Andrzej Doyle On

Firstly, it's worth mentioning that Double[] and double[] are different types, so you cannot pass one in place of another. (Just as you can't call a method that expects int by passing a String).

So you will need to convert your array of Double objects into an array of primitives. If you have no null values, this is simple:

double[] avgsPrim = new double[avg.length];
for (int i = 0; i < avg.length; i++) {
   avgsPrim[i] = avg[i].doubleValue();
}

If any of your values are null, you'll have to think about what this means in this context, and how you can handle that. (Skip it? Substitute it with Double.NaN? Throw an IllegalArgumentException?)