简单例子:
public class JFreeChartAction extends Action {
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
// TODO Auto-generated method stub
JFreeChart jfreechart = createChart(createDataset());
OutputStream out = response.getOutputStream();
JfreeChartService.getChart(out,jfreechart,400, 300);
return mapping.findForward("fuck");
}
private static XYDataset createDataset()
{
XYSeries xyseries = new XYSeries("First");
xyseries.add(1.0D, 1.0D);
xyseries.add(2D, 4D);
xyseries.add(3D, 3D);
xyseries.add(4D, 5D);
xyseries.add(5D, 5D);
xyseries.add(6D, 7D);
xyseries.add(7D, 7D);
xyseries.add(8D, 8D);
XYSeries xyseries1 = new XYSeries("Second");
xyseries1.add(1.0D, 5D);
xyseries1.add(2D, 7D);
xyseries1.add(3D, 6D);
xyseries1.add(4D, 8D);
xyseries1.add(5D, 4D);
xyseries1.add(6D, 4D);
xyseries1.add(7D, 2D);
xyseries1.add(8D, 1.0D);
XYSeriesCollection xyseriescollection = new XYSeriesCollection();
xyseriescollection.addSeries(xyseries);
xyseriescollection.addSeries(xyseries1);
return xyseriescollection;
}
private static JFreeChart createChart(XYDataset xydataset)
{
JFreeChart jfreechart = ChartFactory.createXYLineChart("Line Chart Demo", "X", "Y", xydataset, PlotOrientation.VERTICAL, true, true, false);
XYPlot xyplot = (XYPlot)jfreechart.getPlot();
XYLineAndShapeRenderer xylineandshaperenderer = new XYLineAndShapeRenderer();
xylineandshaperenderer.setSeriesLinesVisible(0, false);
xylineandshaperenderer.setSeriesShapesVisible(1, false);
xylineandshaperenderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator());
xyplot.setRenderer(xylineandshaperenderer);
NumberAxis numberaxis = (NumberAxis)xyplot.getRangeAxis();
numberaxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
return jfreechart;
}
}
****************************************************************************************************
基本思路对了,但是,大大,能做到这种线图和点图混合吗?
你的图里哪有点啊,不就是水平网格线吗?
**************************************** 代 码 ***********************************************
public class JFreeChartAction extends Action {
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
// TODO Auto-generated method stub
JFreeChart jfreechart = createChart(createDataset());
OutputStream out = response.getOutputStream();
JfreeChartService.getChart(out,jfreechart,400, 300);
return mapping.findForward("fuck");
}
private static XYDataset createDataset()
{
XYSeries xyseries = new XYSeries("Series");
xyseries.add(1.0D, 3D);
xyseries.add(2D, 4D);
xyseries.add(3D, 2D);
xyseries.add(6D, 3D);
XYSeriesCollection xyseriescollection = new XYSeriesCollection();
xyseriescollection.addSeries(xyseries);
return xyseriescollection;
}
private static JFreeChart createChart(XYDataset xydataset)
{
JFreeChart jfreechart = ChartFactory.createXYLineChart("JFreeChart Demo", "X", "Y", xydataset, PlotOrientation.VERTICAL, true, true, false);
XYPlot xyplot = (XYPlot)jfreechart.getPlot();
xyplot.setBackgroundPaint(Color.white);
xyplot.setDomainGridlinesVisible(false);
xyplot.setRangeGridlinePaint(Color.gray);
xyplot.setRangeGridlinesVisible(true);
XYStepRenderer xysteprenderer = new XYStepRenderer();
xysteprenderer.setSeriesStroke(0, new BasicStroke(2.0F));
xysteprenderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator());
xysteprenderer.setDefaultEntityRadius(6);
xyplot.setRenderer(xysteprenderer);
return jfreechart;
}
}
************************************** 效 果 ********************************************************