Tooltip not coming up within Chart in Dyanmic Reports

0

Hi All,

I'm using JFreeCharts along with DynamicReports for generating charts and reports. I'm trying to get tooltip inside my Chart component by using the below code.

BarRenderer renderer = (BarRenderer) chart.getCategoryPlot().getRenderer();
renderer.setBaseToolTipGenerator(new StandardCategoryToolTipGenerator());

Unfortunately, I'm unable to get the tooltip inside the chart context, Please let me know how to get tooltip inside chart in Dynamic reports.

I'm Copying the entire code here.

public class BarChartReportExecutiveSummaryExample {
 
    /**
     * <p>Constructor for BarChartReport.</p>
     */
    public BarChartReportExecutiveSummaryExample() {
        build();
    }
 
    /**
     * <p>main.</p>
     *
     * @param args an array of {@link String} objects.
     */
    public static void main(String[] args) {
        new BarChartReportExecutiveSummaryExample();
    }
 
    private void build() {
        FontBuilder boldFont = stl.fontArialBold().setFontSize(12);
 
        TextColumnBuilder<String> itemColumn = col.column("Item", "item", type.stringType());
        TextColumnBuilder<Integer> quantityColumn = col.column("Quantity", "quantity", type.integerType());
        TextColumnBuilder<BigDecimal> unitPriceColumn = col.column("Unit price", "unitprice", type.bigDecimalType());
 
        try {
            BarChartBuilder barChartBuilder1 = cht.barChart()
                    .setTitle("Bar chart")
                    .customizers(new ExecutiveSummaryChartCustomizer())
                    .setOrientation(Orientation.HORIZONTAL)
                    .setFixedHeight(300)
                    .setFixedWidth(300)
                    .setTitleFont(boldFont)
                    .setCategory(itemColumn)
                    .series(cht.serie(quantityColumn), cht.serie(unitPriceColumn))
                    .setCategoryAxisFormat(cht.axisFormat().setLabel("Item"));
 
            report().setTemplate(Templates.reportTemplate)
                    .setPageFormat(950,900,PageOrientation.PORTRAIT)
                    .title(Templates.createTitleComponent("BarChart"))
                    .summary(cmp.horizontalList(barChartBuilder1))
                    .pageFooter(Templates.footerComponent)
                    .setDataSource(createDataSource())
                    .toPdf(new FileOutputStream("C:\\Work\\BotSinkMR2Branch963\\BotSink\\main\\src\\user_interface\\Configurator\\dist\\test.pdf"))
                    .show();
 
        } catch (DRException e) {
            e.printStackTrace();
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }
    }
 
    private JRDataSource createDataSource() {
        DRDataSource dataSource = new DRDataSource("item", "quantity", "unitprice");
        dataSource.add("Tablet", 350, new BigDecimal(300));
        dataSource.add("Laptop", 300, new BigDecimal(500));
        dataSource.add("Smartphone", 450, new BigDecimal(250));
        return dataSource;
    }
 
    public static class ExecutiveSummaryChartCustomizer implements DRIChartCustomizer, Serializable {
        private static final long serialVersionUID = 1L;
        @Override
        public void customize(JFreeChart chart, ReportParameters reportParameters) {
            BarRenderer renderer = (BarRenderer) chart.getCategoryPlot().getRenderer();
            renderer.setBaseToolTipGenerator(new StandardCategoryToolTipGenerator());
 
            renderer.setBaseCreateEntities(true);
            renderer.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator());
            renderer.setBaseItemLabelsVisible(true);
        }
    }
}

Thanks in advance.

abhijith142's picture
Joined: Nov 14 2018 - 1:57am
Last seen: 12 months 2 days ago

0 Answers:

No answers yet
Feedback
randomness