jfreechart生成饼状图,web显示

servlet中部分代码:

    public void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {


        Font titleFont = new Font("黑体",Font.CENTER_BASELINE,18);
        String unitSytle = "{0}:({1},{2})";
        DefaultPieDataset data = getDataSet();
        JFreeChart chart = ChartFactory.createPieChart3D("饼状图", data, true,
                false, false);
        //设置图片的背景色
        chart.setBackgroundPaint(new Color(215,215,215));
       
        //设置透明度,好像对servlet没有用
        chart.setBackgroundImageAlpha(0.5f);
       
        //设置图片标题的字体和大小
        TextTitle _title = new TextTitle("水果产量图");
       
        _title.setFont(titleFont);
        chart.setTitle(_title);   
        PiePlot3D plot=(PiePlot3D)chart.getPlot();
        plot.setNoDataMessage("无对应的数据,请重新查询。");
        plot.setNoDataMessagePaint(Color.red);
       
        //指定 section 轮廓线的厚度(OutlinePaint不能为null)
        plot.setOutlineStroke(new BasicStroke(0));
       
        //设置第一个 section 的开始位置,默认是12点钟方向
        plot.setStartAngle(90);           
       
        //指定图片的透明度
        plot.setForegroundAlpha(0.65f);
       
        //引出标签显示样式
        plot.setLabelGenerator(new StandardPieSectionLabelGenerator(unitSytle,
                NumberFormat.getNumberInstance(),
                new DecimalFormat("0.00%")));
           
        //图例显示样式
        plot.setLegendLabelGenerator(new StandardPieSectionLabelGenerator(unitSytle,
                NumberFormat.getNumberInstance(),
                new DecimalFormat("0.00%")));
       

        OutputStream os = response.getOutputStream();
        response.setContentType("image/png");

        ChartUtilities.writeChartAsPNG(os, chart, 600, 350);

        os.close();
    }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

胡矣

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值