Jfree实现柱状图1

public class WriteImage {

   

   


   
public String writeBarImage(HttpSession session, PrintWriter pw) {

       
//默认种类的数据源

        DefaultCategoryDataset defaultcategorydataset = new DefaultCategoryDataset();

       

       
//生成自己的数据信息

        StudentInfoManager studentInfoManager = new StudentInfoManager();

        List result
= studentInfoManager.getStudentInfo();

       
for(int i = 0, n = result.size(); i < n; i++) {

            StudentInfo studentInfo
= (StudentInfo) result.get(i);

           
//参数(1.显示数据,2.数据标识名,3.数据持有对象)

            defaultcategorydataset.addValue(studentInfo.getStudentPlanAch(),"计划得分", studentInfo.getStudentName());

            defaultcategorydataset.addValue(studentInfo.getStudentAchievement(),
"实际得分", studentInfo.getStudentName());

        }

       

       


        JFreeChart jfreechart
= ChartFactory.createBarChart("JFreeChart测试", "中信学生得分", "得分", defaultcategorydataset, PlotOrientation.VERTICAL, true, true, false);

       

       
//设置当前jfreechart图片的背景颜色

        jfreechart.setBackgroundPaint(Color.white);

       

       
//获取当前jfreechart的点线种类

        CategoryPlot categoryplot = jfreechart.getCategoryPlot();

       
//设置棒状图区域的背景颜色为灰色

        categoryplot.setBackgroundPaint(Color.BLUE);

       

       


       
//设置棒状图区域的主格子线条为白色

        categoryplot.setDomainGridlinePaint(Color.white);

       

       
//将主格子线条设置为可视

        categoryplot.setDomainGridlinesVisible(true);

       

       


       
//设置棒状图区域行列的格子线条的颜色

        categoryplot.setRangeGridlinePaint(Color.red);

        categoryplot.setRangeGridlinesVisible(
true);

       

       

       
//设置数字轴,获取当前数字轴的,也就是纵向的轴

        NumberAxis numberaxis = (NumberAxis)categoryplot.getRangeAxis();

       

       
//设置当前数字轴的单位

        numberaxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());

       

       
//设置棒状图的样式设置

        BarRenderer barrenderer = (BarRenderer)categoryplot.getRenderer();

        barrenderer.setDrawBarOutline(
false);

       

       
//渐变颜色

        GradientPaint gradientpaint = new GradientPaint(0.0F, 8.0F, Color.LIGHT_GRAY, 1.0F, 1.0F, new Color(0, 0, 64));

        GradientPaint gradientpaint1
= new GradientPaint(1.0F, 9.0F, Color.green, 1.0F, 1.0F, new Color(0, 64, 0));

       

        barrenderer.setSeriesPaint(
0, gradientpaint);

        barrenderer.setSeriesPaint(
1, gradientpaint1);

       

       
//添加鼠标提示信息

        barrenderer.setToolTipGenerator(new StandardCategoryToolTipGenerator());

       

       
//获取横向的轴也就是主轴

        CategoryAxis categoryaxis = categoryplot.getDomainAxis();

        categoryaxis.setCategoryLabelPositions(CategoryLabelPositions.createUpRotationLabelPositions(
0.52359877559829882D));

       
//设置图片的绘制信息

        ChartRenderingInfo info = new ChartRenderingInfo(new StandardEntityCollection());

      

        String filename
= null;

       
try {

            filename
= ServletUtilities.saveChartAsPNG(jfreechart, 500, 300, info, session);



           
//  Write the image map to the PrintWriter

            ChartUtilities.writeImageMap(pw, filename, info, false);

           

            pw.flush();

        }
catch (IOException e) {

            e.printStackTrace();

        }

       
return filename;

    }



}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值