• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Using JFreeCharts

 
Ranch Hand
Posts: 2206
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can someone help me with using the JFreeCharts in my JSP-Servlet Web App? Do I create a class for the generation of the chart, call it from my servlet, then display it on the JSP? I really need help with this.
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The way to use JFreeChart in a web app is really by using of the cewolf tag library. Its web site has a tutorial that shows how to use the most important features.
 
Steve Dyke
Ranch Hand
Posts: 2206
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This looks good. But every chart in my app will have to be printed to a pdf file. Can I do this with Cewolf charts?
 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No, I don't think there's anything PDF-related in JFreeChart. But once you have the rendered image you should be able to grab it from the session, save it to disk, and embed it in a PDF. The iText library makes this quite easy.
 
Steve Dyke
Ranch Hand
Posts: 2206
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How do I go about grabing it from the session and saving it to disk? Also, I am using JasperReports for text reports. Can I use JasperReports to make the charts I save printable?
 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The basic way to grab an image from cewolf's session data is as follows. The "img" parameter is the same one that's used in the img tag that generates the chart.

The tricky part is to get at that "img" parameter. You could use the cewolf:imgurl tag to put the URL into a JavaScript variable, and then parse the "img=....." part out of it. Then you can write the link to the PDF in a JavaScript document.write statement. A hack, admittedly, but not hard to implement.



Once you have the bytes of the image, you can iText's Image.getInstance() method to get an Image object that you can add to a Document.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic