简体   繁体   English

DynamicReport-如何绘制太多数据点

[英]DynamicReport - How to plot too many data points

I am trying to create LineChartReport using more than 1000 data points. 我正在尝试使用1000多个数据点创建LineChartReport。 Problem is that the X Axis should show the time stamp, and since there are too many data points, the data gets overlapped and no comprehensible data is shown. 问题是X轴应该显示时间戳,并且由于数据点太多,因此数据重叠并且没有显示可理解的数据。 So I need help on following 2 points: 1. Limit the data points on X-Axis (only) to say 25. The number of data points for the graph/chart still remains at 1000 2. Rotate the Timestamp data by 90 degrees so that the Timestamp data is recorded correctly and not truncated. 因此,我需要以下2点的帮助:1.将X轴上的数据点(仅)限制为25。图形/图表的数据点数量仍为1000。2.将Timestamp数据旋转90度,这样时间戳数据已正确记录且未被截断。

Have tried to get the domain axis and manipulate it, like this, but the library does not allow that:

CategoryAxis domainAxis = chart.getCategoryPlot().getDomainAxis();
domainAxis.setMinorTickMarksVisible(false);
domainAxis.clearCategoryLabelToolTips();
chart.getCategoryPlot().getDataset().getColumnKeys()
CategoryDataset ds = chart.getCategoryPlot().getDataset();
List ls = ds.getColumnKeys();
List ls2 = new ArrayList();

int i = 0;
for (Iterator it = ls.iterator(); it.hasNext(); ) {
    it.next(); 
    if (i % 2 != 0) {
        ls2.add(ls.get(i));
    }
    i++;
}
chart.getCategoryPlot().setDataset(ds);



Sample image with 10 data points appear here: https://drive.google.com/drive/u/0/folders/0B-m6SCJULOTRdHZ6cUwxX041SHM

Any suggestions ??

The below codes are based on DynamicReport 4.0.2. 以下代码基于DynamicReport 4.0.2。 I didn't test them in other versions. 我没有在其他版本中测试过它们。

Regarding your first question, you want 1000 points of data, and just want the few data in line chart. 关于第一个问题,您需要1000点数据,而只需要折线图中的少量数据。 In this case, you need to use the different data source for you data table and line chart. 在这种情况下,您需要为数据表和折线图使用其他数据源。

Firstly, create the subreport for the data table and set up. 首先,为数据表创建子报表并进行设置。

SubreportBuilder subreport = cmp.subreport(
    report().setTemplate(Templates.reportTemplate)
            .addColumn(
                col.column("Name", "name", type.stringType()), 
                col.column("Counts", "value", type.integerType())
            )
);
JasperReportBuilder reportContent = report();
subreport.setDataSource(allDatasource);
reportContent.summary(subreport, cmp.verticalGap(20));

Secondly, prepare another data source for line chart and set up. 其次,为折线图准备另一个数据源并进行设置。

reportContent.setTemplate(Templates.reportTemplate)
    /* add title */
    .title(title, subtitle,
    /* add chart in the head of title */
    cmp.verticalList(LINE_CHART)
    /* set style */ 
    .setStyle(stl.style().setBottomPadding(30).setTopPadding(30)))
    /* set data source for line chart*/
    .setDataSource(dataSource);

About your second question, you need to create customizer at first. 关于第二个问题,首先需要创建定制程序

public class DynamicLineCustomizer implements DRIChartCustomizer, Serializable {
private static final long serialVersionUID = -8493880774698206000L;

@Override
public void customize(JFreeChart jFreeChart, ReportParameters reportParameters) {
    CategoryPlot plot = jFreeChart.getCategoryPlot();
    CategoryAxis domainAxis = plot.getDomainAxis();
    domainAxis.setCategoryLabelPositions(CategoryLabelPositions
            .createUpRotationLabelPositions(Math.PI / 6.0));
    }
}

Then use this customizer in line chard builder. 然后在chard生成器中使用此定制程序

LineChartBuilder lineChart = cht.lineChart()
    .customizers(new DynamicLineCustomizer())
    .setCategory(columns[0])
    .series(createSeries(columns))
    .setCategoryAxisFormat(cht.axisFormat().setLabel("TimeStamp"))
    .seriesColors(seriesColors);

The line chart and data table will be like below: 折线图和数据表如下所示:

折线图和数据表

This finally worked for me (hope it helps somebody) : 终于对我有用(希望对别人有帮助):

Ref: http://www.dynamicreports.org/forum/viewtopic.php?f=1&t=1046 参考: http : //www.dynamicreports.org/forum/viewtopic.php? f =1& t= 1046

private void build(String startDate, String endDate) {
    TextColumnBuilder<Integer> i = col.column("I", "I", type.integerType());
    TextColumnBuilder<Integer> b = col.column("B", "B", type.integerType());
    TextColumnBuilder<Integer> t = col.column("T", "T", type.integerType());
    TextColumnBuilder<Date> timeColumn = col.column("TimeStamp", "TimeStamp", type.dateType());

    createDataSource(startDate, endDate);

    try {   
        TimeSeriesChartBuilder timeSeriesChartBuilder1 = cht.timeSeriesChart();
        timeSeriesChartBuilder1.series(cht.serie(b), cht.serie(t), cht.serie(i));
        timeSeriesChartBuilder1.setShowShapes(false);
        timeSeriesChartBuilder1.setDataSource(dataSource);
        timeSeriesChartBuilder1.setTimePeriod(timeColumn);
        timeSeriesChartBuilder1.setTimePeriodType(TimePeriod.SECOND);
        timeSeriesChartBuilder1.setTitle("ABC Information");

        JasperReportBuilder builder = report()
                .summary(cht.multiAxisChart(timeSeriesChartBuilder1))
                .setTemplate(Templates.reportTemplate)
                .title(Templates.createTitleComponent("ABC Complete Info"))
                ;    
        builder.show();   
    } catch (Exception e) {
        e.printStackTrace();
    }       
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM