Jump to content
JasperReports Library 7.0 is now available ×

Tooltip not coming up within Chart in Dyanmic Reports


abhijith142

Recommended Posts

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.


Link to comment
Share on other sites

  • Replies 0
  • Created
  • Last Reply

Top Posters In This Topic

Popular Days

Top Posters In This Topic

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...