I’m having another problem with the Timeline object - not sure if I’m using the object incorrectly or not - but I could use some help pinpointing the problem…
Assume I have a graph with a couple of lines in it. I allow the user to hit a ‘Total’ button which creates a third line in the graph containing the sum of the other 2 data points. When I try to add this line to the graph, I get the following errors:
Exception in thread “Thread-10” java.lang.NullPointerException
at com.vaadin.addon.timeline.Timeline.getFirstDateInGraphs(Timeline.java:1675)
at com.vaadin.addon.timeline.Timeline.initNewGraphDataSource(Timeline.java:1477)
at com.vaadin.addon.timeline.Timeline.addGraphDataSource(Timeline.java:1576)
at com.verisign.jart.GenJARTGraphThread.insertLine(GenJARTGraphThread.java:222)
at com.verisign.jart.GenJARTGraphThread.updateTotalLine(GenJARTGraphThread.java:269)
at com.verisign.jart.GenJARTGraphThread.genGraph(GenJARTGraphThread.java:209)
at com.verisign.jart.GenJARTGraphThread.processGraph(GenJARTGraphThread.java:87)
It looks like I’m passing in invalid data. HOWEVER, if I only have one line in my graph and hit the total button, I get a valid second line which lays on top of the original data. So there is something wrong with the way I’m constructing the ‘total’ data. If someone can tell me what I’m doing wrong, I’d be most grateful.
The code that adds the line looks like this - I have edited the routine down to the basics…
public void updateTotalLine(JartGraphLine totJGL, JartGraph jg){
BeanItemContainer<RawRRDData> bic = null;
JartGraphLine jgl = null;
List<RawRRDData> rrdArray = new ArrayList<RawRRDData>();
RawRRDData rrd = null;
RawRRDData rrd1 = null;
Timeline tl = null;
Logger.info("# Graph Lines: " + jg.numJartGraphLines());
for(int i = 0; i < jg.numJartGraphLines(); i++){
jgl = jg.getJartGraphLine(i);
bic = jgl.getBic();
Logger.info("BIC[" + i + "]
size = " + bic.size()); // BIC contains the data points for this line
for(int j = 0; j < bic.size(); j++){
rrd = bic.getItem(bic.getIdByIndex(j)).getBean();
if(i == 0){
rrdArray.add(rrd); // Create the array list on the first line
}
else{ // This section must be wrong - why???
rrd1 = rrdArray.get(j); // Get the value in the array
double v = rrd1.getRValue();
v += rrd.getRValue(); // Add the current data point value
rrd1.setRValue(v);
rrdArray.set(j, rrd1); // Put the value back into the array...
}
}
}
tl = jg.getgTL(); // Get the Timeline Object
bic = new BeanItemContainer<RawRRDData>(RawRRDData.class, null);
bic.addAll(rrdArray); // This is invalid if rrdArray created with more than 1 line...
insertLine(tl, jgl, bic); // This routine (see below) is the one that crashes....
}
private void insertLine(Timeline tl, JartGraphLine jgl, BeanItemContainer<RawRRDData> bic){
jgl.setBic(bic);
if(bic != null){
tl.addGraphDataSource(bic, "RDate", "RVal");
tl.setGraphOutlineColor(bic, new Color(jgl.getColor()));
tl.setGraphLegend(bic, "");
if(jgl.isbHideLine()){ // Don't show this line...
tl.setGraphVisibility(bic, false);
}
}
}
This could be due to the same issue as with the missing legend values when empty data sources are used
#8174 . That issue has been fixed and should be available now as a
Custom Build (If you have a Pro Account).
In the tests I’ve been running, there are either one or two graphs and both have data. If I have only one graph, then the ‘total’ line overlays the original exactly, which is what you would expect. If there are 2 graphs, then I get the exception… I’ll add the sort and see what happens.
Here is the output for 1 graph and for 2 graphs (the first seems to work and the second does not). The code that creates the lines looks like this - it may well be inefficient because I’ve been experimenting with it for a couple of weeks now… trying different ways of adding the 2 lines together and getting the result into the BeanItemContainer.
The output is from my log file. It may well be that I’m doing something wrong in all this… Please let me know if you think your code is correct on this one and I’ll keep digging… Thanks for the help,
Log file output:
Process line 1
Found Dynamic line - idx = 1
Update Dynamic Graph Line(s) here…
Graph Lines: 2
BIC[0]
size = 12
Original Data
0) RDate: Mon Jan 23 10:15:00 EST 2012 Rval: 0.399
RDate: Mon Jan 23 10:20:00 EST 2012 Rval: 0.427
RDate: Mon Jan 23 10:25:00 EST 2012 Rval: 11.211
RDate: Mon Jan 23 10:30:00 EST 2012 Rval: 0.32
RDate: Mon Jan 23 10:35:00 EST 2012 Rval: 0.26
RDate: Mon Jan 23 10:40:00 EST 2012 Rval: 0.33
RDate: Mon Jan 23 10:45:00 EST 2012 Rval: 0.323
RDate: Mon Jan 23 10:50:00 EST 2012 Rval: 0.317
RDate: Mon Jan 23 10:55:00 EST 2012 Rval: 0.288
RDate: Mon Jan 23 11:00:00 EST 2012 Rval: 0.298
RDate: Mon Jan 23 11:05:00 EST 2012 Rval: 3.079
RDate: Mon Jan 23 11:10:00 EST 2012 Rval: 0.29
Line 1 is an existing total line
BIC sorted…
RDate: Mon Jan 23 10:15:00 EST 2012 Rval: 0.399
RDate: Mon Jan 23 10:20:00 EST 2012 Rval: 0.427
RDate: Mon Jan 23 10:25:00 EST 2012 Rval: 11.211
RDate: Mon Jan 23 10:30:00 EST 2012 Rval: 0.32
RDate: Mon Jan 23 10:35:00 EST 2012 Rval: 0.26
RDate: Mon Jan 23 10:40:00 EST 2012 Rval: 0.33
RDate: Mon Jan 23 10:45:00 EST 2012 Rval: 0.323
RDate: Mon Jan 23 10:50:00 EST 2012 Rval: 0.317
RDate: Mon Jan 23 10:55:00 EST 2012 Rval: 0.288
RDate: Mon Jan 23 11:00:00 EST 2012 Rval: 0.298
RDate: Mon Jan 23 11:05:00 EST 2012 Rval: 3.079
RDate: Mon Jan 23 11:10:00 EST 2012 Rval: 0.29
then it displays the one graph, overlaid with the ‘Total’ line
And here is the output with 2 graphs - this one fails:
Update Dynamic Graph Line(s) here…
Graph Lines: 3
BIC[0]
size = 12
Original Data
0) RDate: Mon Jan 23 10:15:00 EST 2012 Rval: 0.399
RDate: Mon Jan 23 10:20:00 EST 2012 Rval: 0.427
RDate: Mon Jan 23 10:25:00 EST 2012 Rval: 11.211
RDate: Mon Jan 23 10:30:00 EST 2012 Rval: 0.32
RDate: Mon Jan 23 10:35:00 EST 2012 Rval: 0.26
RDate: Mon Jan 23 10:40:00 EST 2012 Rval: 0.33
RDate: Mon Jan 23 10:45:00 EST 2012 Rval: 0.323
RDate: Mon Jan 23 10:50:00 EST 2012 Rval: 0.317
RDate: Mon Jan 23 10:55:00 EST 2012 Rval: 0.288
RDate: Mon Jan 23 11:00:00 EST 2012 Rval: 0.298
RDate: Mon Jan 23 11:05:00 EST 2012 Rval: 3.079
RDate: Mon Jan 23 11:10:00 EST 2012 Rval: 0.29
BIC[1]
size = 12
Original Data
RDate: Mon Jan 23 10:15:00 EST 2012 Rval: 0.475
RDate: Mon Jan 23 10:20:00 EST 2012 Rval: 0.824
RDate: Mon Jan 23 10:25:00 EST 2012 Rval: 0.329
RDate: Mon Jan 23 10:30:00 EST 2012 Rval: 0.863
RDate: Mon Jan 23 10:35:00 EST 2012 Rval: 0.328
RDate: Mon Jan 23 10:40:00 EST 2012 Rval: 0.76
RDate: Mon Jan 23 10:45:00 EST 2012 Rval: 0.357
RDate: Mon Jan 23 10:50:00 EST 2012 Rval: 0.475
RDate: Mon Jan 23 10:55:00 EST 2012 Rval: 0.315
RDate: Mon Jan 23 11:00:00 EST 2012 Rval: 0.293
RDate: Mon Jan 23 11:05:00 EST 2012 Rval: 1.216
RDate: Mon Jan 23 11:10:00 EST 2012 Rval: 0.278
Line 2 is an existing total line
BIC sorted…
RDate: Mon Jan 23 10:15:00 EST 2012 Rval: 0.874
RDate: Mon Jan 23 10:20:00 EST 2012 Rval: 1.251
RDate: Mon Jan 23 10:25:00 EST 2012 Rval: 11.540000000000001
RDate: Mon Jan 23 10:30:00 EST 2012 Rval: 1.183
RDate: Mon Jan 23 10:35:00 EST 2012 Rval: 0.5880000000000001
RDate: Mon Jan 23 10:40:00 EST 2012 Rval: 1.09
RDate: Mon Jan 23 10:45:00 EST 2012 Rval: 0.6799999999999999
RDate: Mon Jan 23 10:50:00 EST 2012 Rval: 0.792
RDate: Mon Jan 23 10:55:00 EST 2012 Rval: 0.603
RDate: Mon Jan 23 11:00:00 EST 2012 Rval: 0.591
RDate: Mon Jan 23 11:05:00 EST 2012 Rval: 4.295
RDate: Mon Jan 23 11:10:00 EST 2012 Rval: 0.5680000000000001
Exception in thread “Thread-9” java.lang.NullPointerException
at com.vaadin.addon.timeline.Timeline.getFirstDateInGraphs(Timeline.java:1678)
at com.vaadin.addon.timeline.Timeline.initNewGraphDataSource(Timeline.java:1480)
at com.vaadin.addon.timeline.Timeline.addGraphDataSource(Timeline.java:1579)
at com.verisign.jart.GenJARTGraphThread.insertLine(GenJARTGraphThread.java:215)
at com.verisign.jart.GenJARTGraphThread.updateTotalLine(GenJARTGraphThread.java:276)
at com.verisign.jart.GenJARTGraphThread.genGraph(GenJARTGraphThread.java:201)
at com.verisign.jart.GenJARTGraphThread.processGraph(GenJARTGraphThread.java:87)
at com.verisign.common.rrd.util.GenGraphThread.processQueue(GenGraphThread.java:104)
at com.verisign.common.rrd.util.GenGraphThread.run(GenGraphThread.java:78)
You can see that I picked up the rrd object from one graph line (in the container ‘bic’) and then added it to the rrdArray which later on gets added
to a new container for the total line. I’m not sure exactly how the system crashes, but having the same object in two different containers appears to be causing my problem. When I create a brand new set of rrd objects and add them to the system it works.
There is still something a bit screwy going on because if I only have one line of data then I can actually add the total line. If there are 2 or more lines it fails - and I think it has something to do with the fact that not only is the rrd object in 2 places, but I have modified the internal data.
I’m not going to dig any deeper at the moment - but at least I have a working solution…
My thanks to John for looking at it for me - this time it was my problem, not something in the Timeline object itself…