Dates from timestamps on image map tooltips

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
Steven
Posts: 2
Joined: Thu Feb 07, 2008 12:26 am

Dates from timestamps on image map tooltips

Post by Steven » Thu Feb 07, 2008 12:37 am

Hey,

I've got an XYLineChart, on which my X axis is a bunch of time values, stored as milliseconds since Jan 1 1970. I'm getting this output to a web page through use of a Java Servlet, and am getting the image map to go with it. On the tooltip, how can I alter the text so that I can convert the timestamp to a human readable date?

I've been looking all day through the javadocs, but can't work it out. In particular it seems like I need to make a class implementing XYToolTipGenerator, but I'm not clear on how I would actually use it.

Any help appreciated.

Wetzerk
Posts: 14
Joined: Thu Feb 07, 2008 3:54 pm

Post by Wetzerk » Thu Feb 07, 2008 4:21 pm

I found it easier to use the URL generator, here's what I did below.

First, you need to write a class which implements CategoryURLGenerator (or XY depending on your plot).

For in the generateURL method, I did something like below...

Code: Select all

      public String generateURL(CategoryDataset dataset, int series, 
                                int category) {
 
          Comparable seriesKey = dataset.getRowKey(series);
          Comparable categoryKey = dataset.getColumnKey(category);

          StringBuilder sb = new StringBuilder();
          sb.append("'");
          sb.append(URLUtilities.encode(seriesKey.toString(), "UTF-8"));
          sb.append("','");
          sb.append(URLUtilities.encode(categoryKey.toString(), "UTF-8"));
          sb.append("'");
          return sb.toString();
      }
All you need to do is to convert the timestamp (whether it's the series or category) by using java.sql.Timestamp into your human readable format.

The apply it to your plot..

plot.getRenderer().setBaseItemURLGenerator( new MyNewCategoryURLGenerator(""));[/code]

Steven
Posts: 2
Joined: Thu Feb 07, 2008 12:26 am

Post by Steven » Thu Feb 07, 2008 6:51 pm

Thanks for the reply, I managed to do it earlier by making a class that implements ToolTipTagFragmentGenerator (I actually extended OverLIBToolTipTagFragmentGenerator, as I prefer it) and then wrote my own generateToolTipFragment(String toolTipText) which parses the toolTipText parameter to extract the series name, timestamp, and value. Then convert the timestamp to a date, and assemble a string of all the information back together and call super.generateToolTipFragment(toolTipText), so I still get the niceness of OverLIB.

I'm not sure if that's necessarily the most correct way to do it, but it seems to work and I was running out of time. Thanks for the reply though, I'll take a look at your suggestion when I've got a bit more time to play with it.

Locked