JFreeChart生成图显示在web页面上

来源:互联网 发布:美工考核试题 编辑:程序博客网 时间:2024/06/11 08:53

页面代码:

<img src="../../mvc/chartTest/getChartTest.json" alt="" />

主要java代码:

/**
     * 图表测试
     * @param width 图宽度
     * @param height 高度
     * @param type图类型
     * @return
     */
    @RequestMapping(value="/getChartTest",method=RequestMethod.GET)
    public void getChartTest(Integer width,Integer height,String type,HttpServletResponse response){
      try{  
          response.setContentType("image/png");  
          CategoryDataset  dataset = createBarDataSet2();  
          JFreeChart chart=JFreeChartUtils.createBarChart(dataset, "柱状图", "x", "y",true);
          ChartUtilities.writeChartAsPNG(response.getOutputStream(),chart,600,300,null);
        }catch(Exception ex){
            ex.printStackTrace();
        }
    
    }


1 1
原创粉丝点击