I want to use jfreechart in a servlet ,I allready saw the solution but the code is court and i want exactelly to see how we can introduce the code source java in a servlet web (just the begining)
thinks
using JFreeChart in a servlet
RE: using JFreeChart in a servlet
I hope this helps
The bulk of the code to help yu get started in here! On this site
www-sldnt.slac.stanford.edu/jas/documentation.htm . You will have to make some modifications to the SwingServlet.java. But this is straight forward. I have included it below.
JFreeChartPanel t = createChartPanel(req);
ImageProducer image = convertToGIF(t,req.getParameter("transparent")!=null);
sendAsGIF(req,res,image);
}
/**
* Override me!
*/
protected JFreeChartPanel createChartPanel(HttpServletRequest req)
throws ServletException,IOException
{
Number [][] data = new Integer [][]
{
{new Integer(12), new Integer(13),
new Integer(16), new Integer(98) },
{ new Integer(45), new Integer(78),
new Integer(54), new Integer(15) },
{ new Integer(123), new Integer(15),
new Integer(132), new Integer(14)},
{ new Integer(12), new Integer(14),
new Integer(135), new Integer(18)}
};
CategoryDataSource myDataSource = new DefaultCategoryDataSource(data);
JFreeChart myChart = JFreeChart.createVerticalBarChart(myDataSource);
JFreeChartPanel myChartPanel = new JFreeChartPanel(myChart);
return myChartPanel;
}
Cheers
Private Heath
The bulk of the code to help yu get started in here! On this site
www-sldnt.slac.stanford.edu/jas/documentation.htm . You will have to make some modifications to the SwingServlet.java. But this is straight forward. I have included it below.
JFreeChartPanel t = createChartPanel(req);
ImageProducer image = convertToGIF(t,req.getParameter("transparent")!=null);
sendAsGIF(req,res,image);
}
/**
* Override me!
*/
protected JFreeChartPanel createChartPanel(HttpServletRequest req)
throws ServletException,IOException
{
Number [][] data = new Integer [][]
{
{new Integer(12), new Integer(13),
new Integer(16), new Integer(98) },
{ new Integer(45), new Integer(78),
new Integer(54), new Integer(15) },
{ new Integer(123), new Integer(15),
new Integer(132), new Integer(14)},
{ new Integer(12), new Integer(14),
new Integer(135), new Integer(18)}
};
CategoryDataSource myDataSource = new DefaultCategoryDataSource(data);
JFreeChart myChart = JFreeChart.createVerticalBarChart(myDataSource);
JFreeChartPanel myChartPanel = new JFreeChartPanel(myChart);
return myChartPanel;
}
Cheers
Private Heath