Custom URL

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
Baldyos123

Custom URL

Post by Baldyos123 » Wed Feb 08, 2006 12:40 pm

Hello all,

I'm using JSP and MySQL : I'm having alot of fun with JFREE.

One thing I am stuck with is customizing URLs in an imagemap.

I am doing a timeseries graph (simple) : I would like the url to be different for every data point instead of being
index.html?ID=1,
index.html?ID=2,
index.html?ID=3
etc..

I tried different methods by had no success. Is there a way to re-write the URL's?? here is my code.

JFreeChart chart = ChartFactory.createTimeSeriesChart(
"Line",
"Date",
"price",
dataset1,
true,
true,
true
);

XYPlot plot = (XYPlot) chart.getPlot();
StandardXYItemRenderer renderer = new StandardXYItemRenderer();
XYURLGenerator setURL = new StandardXYURLGenerator();

renderer.setBaseShapesVisible(true);
renderer.setToolTipGenerator(StandardXYToolTipGenerator.getTimeSeriesInstance());

ChartRenderingInfo info = new ChartRenderingInfo(new StandardEntityCollection());

plot.setRenderer(0, renderer);

response.setContentType("text/html");
PrintWriter pw = new PrintWriter(out);

String filename = ServletUtilities.saveChartAsPNG(chart, 450, 400, info, session);
ImageMapUtilities.writeImageMap(pw, filename, info);
pw.flush();
String graphURL = System.getProperty("java.io.tmpdir") + filename;


thank alot in advance

Baldyos123

Post by Baldyos123 » Fri Feb 10, 2006 12:31 pm

bump!

angel
Posts: 899
Joined: Thu Jan 15, 2004 12:07 am
Location: Germany - Palatinate

Post by angel » Fri Feb 10, 2006 2:10 pm

I don't know a way JFreeChart could do such thing. But you can always write you own re-directing servlet which decides on the parameters delivered by JFreeChart.

Jean111

?

Post by Jean111 » Mon Feb 13, 2006 4:22 pm

in order to have in your <map> tag the correcte and customizable href: which class should you change to have...

href="me.jsp?series=0&item=17"
href="test.jsp?series=0&item=16"
href="index.jsp?series=0&item=15"
href="frames.jsp?series=0&item=14"

instead of

href="index.html?series=0&item=17"
href="index.html?series=0&item=16"
href="index.html?series=0&item=15"
href="index.html?series=0&item=14"

thanks

dougclayton
Posts: 6
Joined: Tue Feb 14, 2006 10:56 pm

Post by dougclayton » Wed Feb 15, 2006 7:04 pm

This is easy to do--I've done it. For full control, you need to implement your own version of a URL generator (such as org.jfree.chart.urls.XYURLGenerator or org.jfree.chart.urls.CategoryURLGenerator, depending on your renderer) and then supply that to the renderer. All the URL generator has to do is supply a string given the particular data point, so it can have as complicated an algorithm as you need. **

You may be able to use an existing implementation of a URL generator (see the org.jfree.chart.urls package), but I doubt it, if you need a different base URL for each point.

By the way, this is separate from the image map generator, which takes in a URL (created by a URL generator) and a tooltip and outputs them in image-map format. You don't need to change the image map code at all for this.

Did that help?

** By the way, kudos to David Gilbert, Richard Atkinson, and others who architected JFreeChart. The extensive use of simple (often one-function) interfaces for each separate customization facet is simply brilliant.

Jean111

Post by Jean111 » Thu Feb 16, 2006 7:58 am

ok thanks,

will try soon :P

Locked