Adding a line to a Timeline Object

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);
			}
		}
	}

Any help would be appreciated - thanks,

nbc

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).

Thanks John! I will download this at work tomorrow and let you know if it fixes both problems. Thanks for the help!

nbc

The custom build did fix the ‘legend’ problem, but it did NOT fix this one. If I have more than one line, then it gives me the null pointer exception…

nbc

Hmm… I am still having some trouble getting this reproduced properly.

Could you post the new stack trace, the line numbering of the old one is not valid any more.

Also, do you have any empty data sources in your graph when you do that?

And a third thing I came to think of, could you insert

bic.sort(new Object[] { "RDate" }, new boolean[]
 { true });

before the insertLine(tl, jgl, bic); statement to make sure the container is sorted correctly.

I’ll try that and get you a trace this afternoon.

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.

nbc

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.

Code:


public void updateTotalLine(JartGraphLine totJGL, JartGraph jg){
		BeanItemContainer<RawRRDData> bic = null;
		JartGraphLine jgl = null;
		List<RawRRDData> rrdArray = new ArrayList<RawRRDData>();
		Vector<RawRRDData> vData = new Vector<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);
			if(jgl.isDynamicLine()){
				if(jgl.isTotalLine()){
					Logger.info("Line " + i + " is an existing total line");
				}
				continue;
			}
			bic = jgl.getBic();

			Logger.info("BIC[" + i + "]
 size = " + bic.size());

			Logger.info("Original Data");
			for(int j = 0; j < bic.size(); j++){
				rrd = bic.getItem(bic.getIdByIndex(j)).getBean();
				Logger.info("" + j + ") RDate: " + rrd.getRDate() + "   Rval: " + rrd.getRValue());
				if(i == 0){
					rrdArray.add(rrd);
				}
				else{
					rrd1 = rrdArray.get(j);
					double v = rrd1.getRValue();
					v += rrd.getRValue();
					rrd1.setRValue(v);
					rrdArray.set(j, rrd1);
				}
			}
		}
		
		tl = jg.getgTL();

		bic = new BeanItemContainer<RawRRDData>(RawRRDData.class, null);
		bic.addAll(rrdArray);

		bic.sort(new Object[] { "RDate" }, new boolean[]
 { true });
		
		Logger.info("BIC sorted...");
		for(int j = 0; j < bic.size(); j++){
			rrd = bic.getItem(bic.getIdByIndex(j)).getBean();
			Logger.info("" + j + ") RDate: " + rrd.getRDate() + "   Rval: " + rrd.getRValue());
		}
		
		insertLine(tl, totJGL, bic);
	}

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

  1. RDate: Mon Jan 23 10:20:00 EST 2012 Rval: 0.427
  2. RDate: Mon Jan 23 10:25:00 EST 2012 Rval: 11.211
  3. RDate: Mon Jan 23 10:30:00 EST 2012 Rval: 0.32
  4. RDate: Mon Jan 23 10:35:00 EST 2012 Rval: 0.26
  5. RDate: Mon Jan 23 10:40:00 EST 2012 Rval: 0.33
  6. RDate: Mon Jan 23 10:45:00 EST 2012 Rval: 0.323
  7. RDate: Mon Jan 23 10:50:00 EST 2012 Rval: 0.317
  8. RDate: Mon Jan 23 10:55:00 EST 2012 Rval: 0.288
  9. RDate: Mon Jan 23 11:00:00 EST 2012 Rval: 0.298
  10. RDate: Mon Jan 23 11:05:00 EST 2012 Rval: 3.079
  11. RDate: Mon Jan 23 11:10:00 EST 2012 Rval: 0.29
    Line 1 is an existing total line
    BIC sorted…
  12. RDate: Mon Jan 23 10:15:00 EST 2012 Rval: 0.399
  13. RDate: Mon Jan 23 10:20:00 EST 2012 Rval: 0.427
  14. RDate: Mon Jan 23 10:25:00 EST 2012 Rval: 11.211
  15. RDate: Mon Jan 23 10:30:00 EST 2012 Rval: 0.32
  16. RDate: Mon Jan 23 10:35:00 EST 2012 Rval: 0.26
  17. RDate: Mon Jan 23 10:40:00 EST 2012 Rval: 0.33
  18. RDate: Mon Jan 23 10:45:00 EST 2012 Rval: 0.323
  19. RDate: Mon Jan 23 10:50:00 EST 2012 Rval: 0.317
  20. RDate: Mon Jan 23 10:55:00 EST 2012 Rval: 0.288
  21. RDate: Mon Jan 23 11:00:00 EST 2012 Rval: 0.298
  22. RDate: Mon Jan 23 11:05:00 EST 2012 Rval: 3.079
  23. 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

  1. RDate: Mon Jan 23 10:20:00 EST 2012 Rval: 0.427
  2. RDate: Mon Jan 23 10:25:00 EST 2012 Rval: 11.211
  3. RDate: Mon Jan 23 10:30:00 EST 2012 Rval: 0.32
  4. RDate: Mon Jan 23 10:35:00 EST 2012 Rval: 0.26
  5. RDate: Mon Jan 23 10:40:00 EST 2012 Rval: 0.33
  6. RDate: Mon Jan 23 10:45:00 EST 2012 Rval: 0.323
  7. RDate: Mon Jan 23 10:50:00 EST 2012 Rval: 0.317
  8. RDate: Mon Jan 23 10:55:00 EST 2012 Rval: 0.288
  9. RDate: Mon Jan 23 11:00:00 EST 2012 Rval: 0.298
  10. RDate: Mon Jan 23 11:05:00 EST 2012 Rval: 3.079
  11. RDate: Mon Jan 23 11:10:00 EST 2012 Rval: 0.29
    BIC[1]
    size = 12
    Original Data
  12. RDate: Mon Jan 23 10:15:00 EST 2012 Rval: 0.475
  13. RDate: Mon Jan 23 10:20:00 EST 2012 Rval: 0.824
  14. RDate: Mon Jan 23 10:25:00 EST 2012 Rval: 0.329
  15. RDate: Mon Jan 23 10:30:00 EST 2012 Rval: 0.863
  16. RDate: Mon Jan 23 10:35:00 EST 2012 Rval: 0.328
  17. RDate: Mon Jan 23 10:40:00 EST 2012 Rval: 0.76
  18. RDate: Mon Jan 23 10:45:00 EST 2012 Rval: 0.357
  19. RDate: Mon Jan 23 10:50:00 EST 2012 Rval: 0.475
  20. RDate: Mon Jan 23 10:55:00 EST 2012 Rval: 0.315
  21. RDate: Mon Jan 23 11:00:00 EST 2012 Rval: 0.293
  22. RDate: Mon Jan 23 11:05:00 EST 2012 Rval: 1.216
  23. RDate: Mon Jan 23 11:10:00 EST 2012 Rval: 0.278
    Line 2 is an existing total line
    BIC sorted…
  24. RDate: Mon Jan 23 10:15:00 EST 2012 Rval: 0.874
  25. RDate: Mon Jan 23 10:20:00 EST 2012 Rval: 1.251
  26. RDate: Mon Jan 23 10:25:00 EST 2012 Rval: 11.540000000000001
  27. RDate: Mon Jan 23 10:30:00 EST 2012 Rval: 1.183
  28. RDate: Mon Jan 23 10:35:00 EST 2012 Rval: 0.5880000000000001
  29. RDate: Mon Jan 23 10:40:00 EST 2012 Rval: 1.09
  30. RDate: Mon Jan 23 10:45:00 EST 2012 Rval: 0.6799999999999999
  31. RDate: Mon Jan 23 10:50:00 EST 2012 Rval: 0.792
  32. RDate: Mon Jan 23 10:55:00 EST 2012 Rval: 0.603
  33. RDate: Mon Jan 23 11:00:00 EST 2012 Rval: 0.591
  34. RDate: Mon Jan 23 11:05:00 EST 2012 Rval: 4.295
  35. 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)

Well, the bottom line on this one is that I’m an idiot :slight_smile: Given this code:


          for(int j = 0; j < bic.size(); j++){
                rrd = bic.getItem(bic.getIdByIndex(j)).getBean();
                Logger.info("" + j + ") RDate: " + rrd.getRDate() + "   Rval: " + rrd.getRValue());
                if(i == 0){
                    rrdArray.add(rrd);
                }
etc. etc.

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…

nbc