Interactive SVG charts/images

A discussion forum for JFreeSVG (a fast, lightweight, SVG generator for the Java platform).
Post Reply
Mala
Posts: 8
Joined: Tue Jan 28, 2014 1:06 pm
antibot: No, of course not.

Interactive SVG charts/images

Post by Mala » Tue Jan 28, 2014 1:23 pm

I am drawing a chart using JFreeChart. I would like to get its output in SVG format so using JFreeSVG.
Is it possible to create charts using JFreeChart and attach some handlers to it in the SVG format? For example, in case of bar chart - click on a bar should have a handler(which will drill-down the chart) or click on a legend could be recognized(to take some action on it). Thus, I am looking for a way to attach my handlers to different JFreeChartEntities in its SVG output format to make them interactive at the browser end.

remiohead
Posts: 201
Joined: Fri Oct 02, 2009 3:53 pm
antibot: No, of course not.

Re: Interactive SVG charts/images

Post by remiohead » Tue Jan 28, 2014 4:38 pm

I'll tell what I do to achieve a similar result.

First, give each data point a unique id before it is drawn (requires extending renderers):

Code: Select all

g2.setRenderingHint(SVGHints.KEY_ELEMENT_ID, uniqueId);
We have a UI for assigning actions to be executed for events in the browser (click, mouse out, mouse over, and so on). These events are assigned to the uniqueId for a data point and stored on the server in JSON format.

When the page loads we retrieve the JSON object and attach the event handler (in my case all the details are in the JSON object and I use JQuery):

Code: Select all

 $.getJSON(url, function(data) {
    var dp = $("#"+data.id);
    dp.click(function(e) {
     eval(data.click);
   });
});

Mala
Posts: 8
Joined: Tue Jan 28, 2014 1:06 pm
antibot: No, of course not.

Re: Interactive SVG charts/images

Post by Mala » Fri Feb 07, 2014 8:13 am

Thanks,
Will look into it.

david.gilbert
JFreeChart Project Leader
Posts: 11666
Joined: Fri Mar 14, 2003 10:29 am
antibot: No, of course not.
Contact:

Re: Interactive SVG charts/images

Post by david.gilbert » Fri Jul 25, 2014 2:29 pm

Just for anyone that is interested, this approach has been implemented in Orson Charts, there are some examples here:

http://www.object-refinery.com/blog/blog-20140509.html

…and the same approach will eventually be incorporated into JFreeChart.
David Gilbert
JFreeChart Project Leader

:idea: Read my blog
:idea: Ask your company to buy the JFreeChart Developer Guide
:idea: Check out other products sold by my company Object Refinery Limited

Post Reply