JFreeChart 零散

*

主要是dynamicreports 和 jfreechart结合的时候,进行的一些配置:

1,移除legend的黑色边框

LegendTitle legend = chart.getLegend();
        //legend.setFrame(new BlockBorder(Color.green));
        if(legend!=null){
            legend.setFrame(BlockBorder.NONE);//去除legend的黑线框
        }

2,图的方向调换,

.setOrientation(Orientation.HORIZONTAL)

 3,在dynamic-reports中客制化jfreechart

private class AxisLineCustomizer implements DRIChartCustomizer, Serializable {
        private static final long serialVersionUID = 1L;

        @Override
        public void customize(JFreeChart chart, ReportParameters reportParameters) {
            BarRenderer renderer = (BarRenderer) chart.getCategoryPlot().getRenderer();
            CategoryPlot categoryPlot=chart.getCategoryPlot();
            categoryPlot.setRangeGridlinesVisible(false);//数据区的网格线删除
            
            //chart.getLegend().setFrame(BlockBorder.NONE);//去除legend的黑边框
            LegendTitle legend = chart.getLegend();
            //legend.setFrame(new BlockBorder(Color.green));
            if(legend!=null){
                legend.setFrame(BlockBorder.NONE);//去除legend的黑线框
            }
            
            CategoryAxis domainAxis = categoryPlot.getDomainAxis();
            categoryPlot.setRangeZeroBaselineVisible(true);//显示出0的线
            domainAxis.setAxisLineVisible(false);//不显示x轴的线
            domainAxis.setTickMarksVisible(false);//不显示x轴的标尺
            
            renderer.setNegativeItemLabelPosition(new ItemLabelPosition());
            ValueAxis valueAxis=(ValueAxis) chart.getCategoryPlot().getRangeAxis();
            categoryPlot.setDomainAxisLocation(AxisLocation.BOTTOM_OR_LEFT);
            //domainAxis.setInverted(true);//数据轴倒过来
            //categoryPlot.setOrientation(PlotOrientation.VERTICAL);
        }
    }

4,xy轴的标签

//.setCategoryAxisFormat(cht.axisFormat().setLabel("一万个理由"))//x轴标签
.setValueAxisFormat(cht.axisFormat().setLabel("(%)"))//y轴标签

 *5,.setUseSeriesAsCategory(true)

 *

更多属性设置,参考 JFreeChart中文API

*

有问题在公众号【清汤袭人】找我,时常冒出各种傻问题,然一通百通,其乐无穷,一起探讨


原文地址:https://www.cnblogs.com/qingmaple/p/6170750.html