I am using Dynamicreports4.1.1, whose chart based on Jfreechart.
I want to draw chart like image below:
It somewhat like Candlestickchart or stackedchart or layeredchart.
I choose the stackedchart to customize, it like this:
The code:
public class StackedBarChartReportTest {
public StackedBarChartReportTest() {
build();
}
private void build() {
FontBuilder boldFont = stl.fontArialBold().setFontSize(12);
TextColumnBuilder<String> itemColumn = col.column("Item", "item", type.stringType());
TextColumnBuilder<BigDecimal> bestColumn = col.column("Best", "best", type.bigDecimalType());
TextColumnBuilder<BigDecimal> worstColumn = col.column("Worst", "worst", type.bigDecimalType());
try {
report()
.setTemplate(Templates.reportTemplate)
.columns(itemColumn, bestColumn, worstColumn)
.title(Templates.createTitleComponent("StackedBarChart"))
.summary(
cht.stackedBarChart()
.customizers(new ChartCustomizer())
.setTitle("Stacked bar chart")
.setTitleFont(boldFont)
.setCategory(itemColumn)
.setShowValues(true)
.series(
cht.serie(bestColumn), cht.serie(worstColumn))
.setCategoryAxisFormat(
cht.axisFormat().setLabel("Item")))
.pageFooter(Templates.footerComponent)
.setDataSource(createDataSource())
.show();
} catch (DRException e) {
e.printStackTrace();
}
}
private class ChartCustomizer implements DRIChartCustomizer, Serializable {
private static final long serialVersionUID = 1L;
@Override
public void customize(JFreeChart chart, ReportParameters reportParameters) {
BarRenderer renderer = (BarRenderer) chart.getCategoryPlot().getRenderer();
// here customize,but have no idea...
}
}
private JRDataSource createDataSource() {
DRDataSource dataSource = new DRDataSource("item", "best", "worst");
dataSource.add("1Y", new BigDecimal(-10), new BigDecimal(-14.5));
dataSource.add("2Y", new BigDecimal(10), new BigDecimal(4));
dataSource.add("3Y", new BigDecimal(12), new BigDecimal(-2));
return dataSource;
}
public static void main(String[] args) {
new StackedBarChartReportTest();
}
Have no idea how to start or Is there a chart like this?