我们项目中用的报表工具是ireport + jasperreport
现在我想实现这样的一个柱状图:
现在唯一没有实现的是,上图每个柱的数值没出来,不知道怎么设,没有看到相应的接口!jfreechart是可以设的!BarRenderer3D renderer = new BarRenderer3D();
renderer.setBaseOutlinePaint(Color.BLACK);
//设置 Wall 的颜色
renderer.setWallPaint(Color.gray);
//设置每种水果代表的柱的颜色
renderer.setSeriesPaint(0, new Color(0, 0, 255));
renderer.setSeriesPaint(1, new Color(0, 100, 255));
renderer.setSeriesPaint(2, Color.GREEN);
//设置每个地区所包含的平行柱的之间距离
renderer.setItemMargin(0.1);
//显示每个柱的数值,并修改该数值的字体属性
renderer.setItemLabelGenerator(new StandardCategoryItemLabelGenerator());
renderer.setItemLabelsVisible(true);

plot.setRenderer(renderer);但是jasperreport该怎么设,按理说
它是调用jfreechart来画图的,但我却没找到相应的接口进行设值!请各位大侠帮一下忙!分不够可以加!

解决方案 »

  1.   

    这个很容易   
    LZ可以看下我写过的代码
    public ActionForward outCatgory(ActionMapping mapping, ActionForm form,
    HttpServletRequest request, HttpServletResponse response) {
    DynaActionForm searchForm = (DynaActionForm) form;
    int a = ub.find1("2009");
    int b = ub.find2("2009");
    int c = ub.find3("2009");
    int d = ub.find4("2009");
    FileOutputStream fos_jpg; try {
    fos_jpg = new FileOutputStream("e:\\柱状图分布.jpg");
    DefaultCategoryDataset dataset = new DefaultCategoryDataset(); dataset.addValue(a, "注册人数", "一季度");
    dataset.addValue(b, "注册人数", "二季度");
    dataset.addValue(c, "注册人数", "三季度");
    dataset.addValue(d, "注册人数", "四季度");
    JFreeChart chart = ChartFactory.createBarChart3D("产量图", "时间", "人数",
    dataset, PlotOrientation.VERTICAL, true, true, true); chart.getTitle().setFont(new Font("宋体", Font.BOLD, 12));// 标题中文 CategoryPlot categoryplot = (CategoryPlot) chart.getPlot(); CategoryAxis domainAxis = categoryplot.getDomainAxis(); NumberAxis numberaxis = (NumberAxis) categoryplot.getRangeAxis(); domainAxis.setTickLabelFont(new Font("sans-serif", Font.PLAIN, 11)); // 横轴坐标中文 domainAxis.setLabelFont(new Font("宋体", Font.PLAIN, 12)); // 横轴标题中文 numberaxis.setTickLabelFont(new Font("sans-serif", Font.PLAIN, 12)); // 竖轴坐标中文 numberaxis.setLabelFont(new Font("黑体", Font.PLAIN, 12)); // 竖轴标题中文 chart.getLegend().setItemFont(new Font("宋体", Font.PLAIN, 12)); // 底部中文 ChartUtilities.writeChartAsJPEG(fos_jpg, 1.0f, chart, 640, 480,
    null); // 图片形式画出来
    fos_jpg.close();
    } catch (FileNotFoundException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    } catch (IOException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    } return null;
    }
      

  2.   

    plot 中应该有个 ShowLabels
      

  3.   

    //这儿是坐标上的字体,自己试试....
    JFreeChart chart = ChartFactory.createBarChart3D("隐患质量柱状图", // chart title
        "问题类别", // domain axis label
        "次数", // range axis label
        dataset, // data
        PlotOrientation.VERTICAL, // PlotOrientation.VERTICAL 让平行柱垂直显示,而 PlotOrientation.HORIZONTAL 则让平行柱水平显示
        true, // include legend
        true, // tooltips
        false // urls
        );  chart.setBackgroundPaint(Color.WHITE);
      CategoryPlot plot = chart.getCategoryPlot();
      CategoryAxis domainAxis = plot.getDomainAxis();
      domainAxis.setCategoryMargin(0.15);
      domainAxis.setMaximumCategoryLabelLines(3);
      domainAxis.setMaximumCategoryLabelWidthRatio(3);
      plot.setDomainAxis(domainAxis);
    // 图示在图表中的显示位置  LegendTitle legend = (LegendTitle) chart.getLegend();
      legend.setPosition(RectangleEdge.TOP);    //示意图位置
     // legend.setPosition(RectangleEdge.RIGHT);
      legend.setLegendItemGraphicEdge(RectangleEdge.LEFT);  ValueAxis rangeAxis = plot.getRangeAxis();
      
      //设置最高的一个 Item 与图片顶端的距离
      rangeAxis.setUpperMargin(0.15);
      
      //设置最低的一个 Item 与图片底端的距离
      rangeAxis.setLowerMargin(0.15);
      plot.setRangeAxis(rangeAxis);  BarRenderer3D renderer = new BarRenderer3D();
      renderer.setBaseOutlinePaint(Color.blue);
      
      //设置 Wall 的颜色
      renderer.setWallPaint(Color.darkGray);
      
      renderer.setSeriesPaint(0, Color.red);
      renderer.setSeriesPaint(1, Color.GREEN);
      renderer.setSeriesPaint(2, Color.orange);
      
      //设置每个地区所包含的平行柱的之间距离
      renderer.setItemMargin(0.03);
      
      //显示每个柱的数值(名称),并修改该数值的字体属性
      renderer.setItemLabelGenerator(new StandardCategoryItemLabelGenerator());  renderer.setItemLabelFont(new Font("黑体",Font.PLAIN,12));
      renderer.setItemLabelsVisible(true);
      ItemLabelPosition itemLabelPosition = new ItemLabelPosition();
      renderer.setPositiveItemLabelPosition(itemLabelPosition);
      plot.setRenderer(renderer);  //设置柱的透明度
      plot.setForegroundAlpha(1f);
      
      //设置专业、数量的显示位置
    //  plot.setDrawSharedDomainAxis(true);
      plot.setDomainAxisLocation(AxisLocation.BOTTOM_OR_LEFT);
      plot.setRangeAxisLocation(AxisLocation.BOTTOM_OR_LEFT);
      String filename = ServletUtilities.saveChartAsPNG(chart, 1220, 490, null, session);
      String graphURL = request.getContextPath() + "/servlet/DisplayChart?filename=" + filename;
      

  4.   


    这个我设为true了,每个柱上面就显示一小 "-",不知道是什么原因
      

  5.   

    解决了,原来我设的是对的,在测试画面上,值全是1,然后几个图在一块,显示有点不正常了。
    实际画面一切OK了
    barPlot 设置 isShowLabels="true"散分!
      

  6.   

    看了官方的 http://jasperreports.sourceforge.net/xsd/jasperreport.xsd而且我找到了设置 成百分比的方式显示<valueAxisFormat>
    <axisFormat tickLabelMask="##%">
    <labelFont/>
    <tickLabelFont/>
    </axisFormat>
    </valueAxisFormat>加给以上代码加上 tickLabelMask="##%" 属性当然也可以用ireport直接找到对应的属性进行设置
      

  7.   

    现在又有个新问题
    如上加了tickLabelMask="##%"属性,只能是边上的Y轴的格式变化了我怎么把中间每个柱的数值也改变成相同的格式呢?!没找到对应的属性!高手赐教!
      

  8.   

    <bar3DPlot isShowLabels="true">设过后还是出不来结果啊
      

  9.   

    请问没有用java代码写,直接在ireport里怎么设置?