jfreechart实现点状图和折线图(特殊折线图)效果,求达人成全,图如下:

求指点,求高手!... 求指点,求高手! 展开
 我来答
m瀚霖
2011-06-08 · TA获得超过473个赞
知道小有建树答主
回答量:244
采纳率:0%
帮助的人:188万
展开全部

简单例子:

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;
}
}
************************************** 效 果 ********************************************************
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式