一聚教程网:一个值得你收藏的教程网站

热门教程

用jfreechart绘制水晶效果的拼图实现代码

时间:2022-06-29 02:38:52 编辑:袖梨 来源:一聚教程网

一个水晶效果的拼图如下

image

实现代码如下

 代码如下 复制代码


<%@ page contentType="text/html;charset=GBK"%>
 
 <%@ page
     import="org.jfree.chart.*,org.jfree.chart.servlet.ServletUtilities,
     org.jfree.util.Rotation,org.jfree.data.general.DefaultPieDataset,
     org.jfree.chart.plot.PiePlot3D,org.jfree.chart.title.TextTitle,
     java.awt.Font,org.jfree.chart.plot.PiePlot"%>
 
 <%
     //设置数据集
     DefaultPieDataset dataset = new DefaultPieDataset();
     dataset.setValue("初中高级程序员", 0.52);
     dataset.setValue("项目经理", 0.1);
     dataset.setValue("系统分析师", 0.1);
     dataset.setValue("软件架构师", 0.1);
     dataset.setValue("其他", 0.18);
 
     //通过工厂类生成JFreeChart对象
     JFreeChart chart = ChartFactory.createPieChart3D("IT行业职业分布图",
             dataset, true, true, false);
     //获得3D的水晶图对象
     PiePlot3D pieplot3d = (PiePlot3D) chart.getPlot();
    //设置开始角度
    pieplot3d.setStartAngle(150D);
    //设置方向为“顺时针方向”
    pieplot3d.setDirection(Rotation.CLOCKWISE);
 
    //设置透明度,0.5F为半透明,1为不透明,0为全透明
    pieplot3d.setForegroundAlpha(0.5F);
   
     //没有数据的时候显示的内容
      pieplot3d.setNoDataMessage("无数据显示");
    
      //标题文字乱码  IT行业职业分布图
      TextTitle textTitle = chart.getTitle();
      textTitle.setFont(new Font("宋体", Font.PLAIN, 20));
     
      //饼上的文字乱码
      PiePlot plot = (PiePlot) chart.getPlot();
     plot.setLabelFont(new Font("宋体", Font.PLAIN, 12));
    
      //图例文字乱码 饼图下面的5个说明
      chart.getLegend().setItemFont(new Font("宋体", Font.PLAIN, 12));
     
     String filename = ServletUtilities.saveChartAsPNG(chart, 500, 300,
             null, session);
     String graphURL = request.getContextPath()
             + "/DisplayChart?filename=" + filename;
 %>
 
 
    
         饼状图3(水晶饼图)
    
    
                      usemap="#<%= filename %>">
    
 

热门栏目