Win a copy of TDD for a Shopping Website LiveProject this week in the Testing forum!
  • 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
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

How to link JFreeChart with JSP

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hai,
I want to show my database content using charts(pie chart,line chart...). I am using JSP.
How to link JFreeChart with JSP to show my content in webpage
 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Let me explain one approach I had implemented some time back. I had used jfreechart-1.0.0-pre2

1) Create an org.jfree.data.xy.XYSeries object and add all sets of x-coordinate and y-coordinate in a sample space. you can create as many XYSeries object as number of sample spaces.
2) Create org.jfree.data.xy.XYSeriesCollection object and add all such XYSeries objects in XYSeriesCollection object.
3) Create 2 objects of org.jfree.chart.axis.ValueAxis , one defining x-axis and other defining y-axis. There are numerous types axis classes available in the package like Data, logarithemic , .. etc
4) Create org.jfree.chart.renderer.xy.XYItemRenderer´┐Żobject. Again there are numerous options available for Renderer. Select type of renderer depending type of graph you want.
5) Create org.jfree.chart.plot.XYPlot object using XYSeriesCollection object , ValueAxis objects and XYItemRenderer object as arguments in the constructor
6) Create org.jfree.chart.JFreeChart object using chart title(String) , font, and XYPlot object as arguments in the constructor

7) use org.jfree.chart.servlet.ServletUtilities.saveChartAsPNG() (or use other utility methods) to save the chart in temporary directory
8) Finally use org.jfree.chart.servlet.DisplayChart servlet to display the chart in the JSP page. You need to pass on the temporary chart image file name obtained from ServletUtilities.saveChartAsPNG() to DisplayChart servlet.
i.e <img src="/servlet/DisplayChart?filename=<%=filename%>" width="750" height="450" />

make sure you put the jfreechart jar in your application classpath

hope this helps
 
I'm gonna teach you a lesson! Start by looking at this tiny ad:
free, earth-friendly heat - a kickstarter for putting coin in your pocket while saving the earth
https://coderanch.com/t/751654/free-earth-friendly-heat-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic