how to smooth area chart using dynamicreports?

22 views Asked by At

I'm using dynamicreports to generate different charts ,such as area chart,line chart. and I found could not generate smooth area/line chart using it's defaut settings ,can anybody hlep me ? thanks a lot !

enter image description here the report I generated

enter image description here the report I exptected

public ChartReport() {

            build();

        }

        private void build() {
            File file = new File("d:/report.pdf");
            if (!file.exists()) {
                //LOGGER.info("creating folder");
                file.mkdir();
                file.setWritable(true);
            }

            JasperPdfExporterBuilder pdfExporter = export.pdfExporter("d:/report.pdf");
            JasperXlsExporterBuilder xlsExporter = export.xlsExporter("d:/report.xls");
            JasperDocxExporterBuilder dcoxExporter = export.docxExporter("d:/report.docx");


            FontBuilder boldFont = stl.fontArialBold().setFontSize(12);

            TextColumnBuilder<String> xColumn = col.column("X测试", "x", type.stringType());

            TextColumnBuilder<Double> y1Column = col.column("Y1", "y1", type.doubleType());

            TextColumnBuilder<Double> z1Column = col.column("Z1", "z1", type.doubleType());

            TextColumnBuilder<Double> y2Column = col.column("Y2", "y2", type.doubleType());

            TextColumnBuilder<Double> z2Column = col.column("Z2", "z2", type.doubleType());

            try {


        

                AreaChartBuilder  areaChart = cht.areaChart()
                                       .setTitle("")
                                        //.setTitleFont()
                                         .setCategory(xColumn)
                                        .series(cht.serie(y1Column))
                                        //.setCategoryAxisFormat(cht.axisFormat().setLabel("新颖"))
                                        .addCustomizer(new AreaChartCustomizer());



                report()
                        .setTemplate(Templates.reportTemplate)
                        .title(Templates.createTitleComponent(""),areaChart  )
                        .columns(xColumn, y1Column, z1Column, y2Column, z2Column)
                        .pageFooter(Templates.footerComponent)
                        .setDataSource(createDataSource())
                        .show()
                        //.toDocx(dcoxExporter);
                        //.toXls(xlsExporter);
                        .toPdf(pdfExporter);


               /* // 导出报告为PDF或HTML
                FileOutputStream fos = new FileOutputStream("output/example.pdf");
                report.show();
                report.exportToPdf(fos);*/


            } catch (DRException e) {

                e.printStackTrace();

            }

        }

        private JRDataSource createDataSource() {

            DRDataSource dataSource = new DRDataSource("x", "y1", "z1", "y2", "z2");

            for (int i = 0; i < 5; i++) {
                dataSource.add(String.valueOf(i) + "新颖", Math.random() * 10, Math.random() * 2, Math.random() * 8, Math.random() * 3);
            }

            return dataSource;

        }


    private class AreaChartCustomizer implements DRIChartCustomizer, Serializable {
        public void customize(JFreeChart chart, ReportParameters reportParameters) {
            CategoryAxis domainAxis = chart.getCategoryPlot().getDomainAxis();
            domainAxis.setCategoryLabelPositions(CategoryLabelPositions.createUpRotationLabelPositions(45));

            CategoryPlot plot = (CategoryPlot) chart.getPlot();
            AreaRenderer areaRenderer = (AreaRenderer) plot.getRenderer();
            areaRenderer.setSeriesPaint(0,new Color(169,188,237),true);
            //((NumberAxis)plot.getRangeAxis()).setAutoRangeIncludesZero(false);

            
        }
    }



        public static void main(String[] args) {

            new ChartReport();

        }
0

There are 0 answers