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.
Dates from timestamps on image map tooltips
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...
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]
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();
}
The apply it to your plot..
plot.getRenderer().setBaseItemURLGenerator( new MyNewCategoryURLGenerator(""));[/code]
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.
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.