February 13, 2011

JFreeChart with Links in a JSP

Starts Jetty WebServer on port 8085 with a dynamic JFreeChart example with links inside the image.

Download

SVN location: https://carlosrodriguezdev.googlecode.com/svn/20110111_JFreeChar_BarChart


How to Run

1 - mvn jetty:run
2 - on your browser: http://localhost:8085
3 - click on the link that will appear

You should see:

Click the Image



How it Works

barchart.BarChartGerador
Creates the BarChart
barchart.PendenciaBarRenderer
Extends BarRenderer3D making it possible to change Bar Colors the way you want.
barchart.PendenciaData
Carries all the attributes necessary for every row in the chart. It's a POJO.
barchart.PendenciaDataset
Handles which bars should be created for each PendenciaData. Usually a chart has 1 bar for each Item, but this one, for example, has 2.
barchart.PendenciaURLGenerator
Lets you customize all the links inside the chart image
index.jsp
<%
    PendenciaDataset dataset = BarChartGerador.mockCriarDataset();
    // generates the <MAP> in the JSP for all the links inside the chart image
    BarChartGerador grafico = new BarChartGerador("JFreeChart - Bar Chart Example", dataset, session, new PrintWriter(out));
    String filename = grafico.getFilename();
    String graficoGeradoURL = request.getContextPath() + "/servlet/DisplayChart?filename=" + filename;
%>
<img src="<%= graficoGeradoURL %>" border=0 usemap="#<%= filename %>">

4 comments:

  1. Thanks for sharing. Which version of JFreeChart are you using?

    ReplyDelete
  2. I see in you .pom it is 0.9.20 - very old

    ReplyDelete
  3. np
    yes, it was for a legacy system, this example is compatible with 1.0.0, but i'm not sure about newer versions

    ReplyDelete
  4. hi.. thanks for sharing.. I have to create a bar chart in struts 1.2, using db values. Can u plz guide me how to approach / if any working example code if u can share.. its urgent... thnx in advance..

    ReplyDelete