日期:2014-05-20  浏览次数:20728 次

用jsp怎样生成柱状图,饼状图,折线图
现在,javaEE学完了,做个小项目练习练习,期中有一块 报表,想生成 柱状图 或者饼状图 或者折线图。

学 c/s 的时候在 面板上生成的,但在jsp页面上做不出来了,先谢谢大家。

------解决方案--------------------
用jfreechart插件,开源的,你自己写?没多大意义,除非你要炼身手,呵
------解决方案--------------------
jfreechart不错,还可以做一些温度计啦仪表盘啦,好多好可视化的图形,最重要的是免费的,使用起来比较简单
------解决方案--------------------
EN ,JFREECHART,很好,很简单!
------解决方案--------------------
http://blog.csdn.net/Ami121/category/394379.aspx
一些jfreechart的例子
jfreechat插件对于画web是个不错的选择
当然你也可以做成applet形式直接嵌入到jsp中
------解决方案--------------------
探讨
谢谢大家,jfreechart是很好,但我不会用啊。

------解决方案--------------------
我这里有现成的例子,需要的话,就把邮箱告诉我,给你发过去
------解决方案--------------------
又多了解了一个插件Jfreechart
------解决方案--------------------
我给你一个饼图和一个折线图的例子,你看看!
饼图的
Java code

class   BChart{
public static void main(String[] args){
                         PieDataset dataset = getDataSet();//设置数据源 
             JFreeChart chart = ChartFactory.createPieChart3D(
                "时延分布统计图", // chart title
                dataset,// data
                true,// include legend
                true,
                false
               );
              PiePlot3D  plot=(PiePlot3D)chart.getPlot();
                // 图片中显示百分比:默认方式
                //plot.setLabelGenerator(new                         StandardPieSectionLabelGenerator(StandardPieToolTipGenerator.DEFAULT_TOOLTIP_FORMAT));
            // 图片中显示百分比:自定义方式,{0} 表示选项, {1} 表示数值, {2} 表示所占比例 ,小数点后两位
             plot.setLabelGenerator(new StandardPieSectionLabelGenerator("{0}={1}({2})", NumberFormat.getNumberInstance(), new DecimalFormat("0.00%"))); 
            // 图例显示百分比:自定义方式, {0} 表示选项, {1} 表示数值, {2} 表示所占比例                
             plot.setLegendLabelGenerator(new StandardPieSectionLabelGenerator("{0}={1}({2})")); 
            // 设置背景色为白色 
            chart.setBackgroundPaint(Color.white); 
            // 指定图片的透明度(0.0-1.0) 
             plot.setForegroundAlpha(1.0f); 
            // 指定显示的饼图上圆形(false)还椭圆形(true) 
            plot.setCircular(true); 
            // 设置图标题的字体 
            Font font = new Font(" 黑体",Font.CENTER_BASELINE,20); 
            TextTitle title = new TextTitle(" 时延分布统计图"); 
            title.setFont(font);  
            chart.setTitle(title); 
            FileOutputStream fos_jpg = null; 
            try { 
                 fos_jpg=new FileOutputStream("D:\\时延分布统计图.jpg"); 
                 ChartUtilities.writeChartAsJPEG(fos_jpg,100,chart,640,480,null); 
                 fos_jpg.close(); 
            } catch (Exception e) { 
             } 
            
          }
        
    private static PieDataset getDataSet()//数据源构造
        { 
            DefaultPieDataset dataset = new DefaultPieDataset(); 
        
            dataset.setValue("login.jsp",50); 
                        dataset.setValue("reg.jsp",60); 

            return dataset; 
        } 
}

------解决方案--------------------
折线图的
Java code

class ZChart{
public static void main(String[] args)
{
JFreeChart chart = ChartFactory.createXYLineChart("固定uri时延分布图", "历次访问点",
                "时延/ms", createDataSet(special), PlotOrientation.VERTICAL, true,
                true, false);
    
        FileOutputStream fos_jpg = null; 
        try { 
             fos_jpg=new FileOutputStream("D:\\mao.jpg"); 
             ChartUtilities.writeChartAsJPEG(fos_jpg,100,chart,640,480,null); 
             fos_jpg.close(); 
        } catch (Exception e) { 
         } 
        
    
    
    
      }
    
    
    private static XYSeriesCollection createDataSet() {//数据源构造方法
        XYSeriesCollection seriesCollection = new XYSeriesCollection();
        XYSeries series1 = new XYSeries("login.jsp");
        
    
        seriesCollection.addSeries(series1);

        series1.add(1, 75);
        series1.add(2, 41);
        series1.add(3, 39);
        series1.add(4, 33);
        series1.add(5, 25);
        series1.add(6, 36);


        seriesCollection.addSeries(series1);
        
        return seriesCollection;
    }

}