MyException - 我的异常网
当前位置:我的异常网» J2EE » 用jsp怎的生成柱状图,饼状图,折线图

用jsp怎的生成柱状图,饼状图,折线图(4)

www.myexceptions.net  网友分享于:2013-12-22  浏览:982次

</div>
<script type="text/javascript">
  var myChart = new FusionCharts("Gantt8.swf", "myChartId", "900", "450", "0", "0");
  myChart.setDataURL("Gantt8.xml");
myChart.render("chartdiv");
</script> </td>
</tr>
<tr height='10'>
<td></td>
</tr>
<tr>
<td align="center" class="text">Using legend in the chart to explain color keys. </td>
</tr>
<tr>
<td align="center">&nbsp;</td>
</tr>
<tr>
<td align="center">
<a href='Gantt8.xml' target='_blank'><img src='btnViewXML8.gif' border='0' alt='View XML for above chart' width="94" height="24" ></a> </td>
</tr>
</table>
</body>
</html>
------解决方案--------------------
我记得老师讲的用jfreechart 很方便的
------解决方案--------------------
Java code

public void appStatView() throws SQLException{
        
        HttpServletRequest request = ServletActionContext.getRequest();
        HttpServletResponse response = ServletActionContext.getResponse();
        HttpSession session = request.getSession();
        
        Connection con = null;
        PreparedStatement pst = null;
        ResultSet rs = null;
        PrintWriter out = null;
        
        try {
            //获取驱动连接
            con = this.getConnection();
        
                        //数据源的获得,具体省略。。。。。。

            rs = pst.executeQuery();
            
            Font font = new Font("宋体", 10, 15);
            
//            设置数据集
            DefaultCategoryDataset dataset = new DefaultCategoryDataset();
            while(rs.next()) {
                dataset.setValue(rs.getInt("sum"), rs.getString("app_name"), rs.getString("app_name"));
            }
//            通过工厂类生成JFreeChart对象
            JFreeChart chart = ChartFactory.createBarChart3D("系统登陆统计", "业务系统", "登陆次数", dataset, 
                    PlotOrientation.VERTICAL, true, true, false);
                   
            TextTitle title = chart.getTitle();
            
            title.setFont(font);
            
            CategoryPlot plot = chart.getCategoryPlot();
            
            CategoryAxis domainAxis = plot.getDomainAxis();//获取横轴
            domainAxis.setLabelFont(font);
            domainAxis.setTickLabelFont(font);
            
            ValueAxis rangeAxis = plot.getRangeAxis();//获取纵轴
            rangeAxis.setLabelFont(font);  
            
            chart.getLegend().setItemFont(font);
            
            String filename = ServletUtilities.saveChartAsPNG(chart, 1000, 400, null, session);//生成文件
            String graphURL = request.getContextPath() + "/DisplayChart?filename=" + filename;//生成文件URL
            
            sb = new StringBuilder();
            sb.append("<img src='" + graphURL + "' height=400 border=0 style='width:100%' />");
            
            out = response.getWriter();
            out.write(sb.toString());
        }catch(Exception e) {
            e.printStackTrace();
        }finally {//释放资源
            if(out != null) {
                out.close();
            }
            
            if(rs != null) {
                rs.close();
            }
            
            if(pst != null) {
                pst.close();
            }
            
            if(con != null) {
                con.close();
            }
        }
    }

------解决方案--------------------
Jfreechart
------解决方案--------------------

文章评论

软件开发程序错误异常ExceptionCopyright © 2009-2015 MyException 版权所有