Jump to content
We've recently updated our Privacy Statement, available here ×

sgolestane

Members
  • Posts

    10
  • Joined

  • Last visited

 Content Type 

Profiles

Forum

Events

Featured Visualizations

Knowledge Base

Documentation (PDF Downloads)

Blog

Documentation (Test Area)

Documentation

Dr. Jaspersoft Webinar Series

Downloads

Everything posted by sgolestane

  1. Here is how i fixed this problem: in ChartLabelCustomizer I add a ChangeListener to piePlot to listen for DATASET_UPDATED events and set section colors based on the value of dataset keys. see the attached code for more details Code: colorMap.put("KEY-1", Color.decode("#ff6666")); colorMap.put("KEY-2", Color.decode("#6666ff")); colorMap.put("KEY-3", Color.decode("#66ff66")); final PieDataset dataset = piePlot.getDataset(); piePlot.addChangeListener(new PlotChangeListener() { public void plotChanged(PlotChangeEvent event) { if(event.getType() == ChartChangeEventType.DATASET_UPDATED) { //Assign color to each section of pie chart based on value of key for (int i = 0; i < dataset.getItemCount(); i++) { setSectionColor(piePlot, dataset.getKey(i), "KEY-1"); setSectionColor(piePlot, dataset.getKey(i), "KEY-2"); setSectionColor(piePlot, dataset.getKey(i), "KEY-3"); } } } }); private void setSectionColor(PiePlot piePlot, Comparable key, String parterName) { if(key.toString().toLowerCase().contains(parterName)) { piePlot.setSectionPaint(key, colorMap.get(parterName)); } }
  2. I'm using keyExpression, valueExpression and labelExpression to pass data to the chart and chart renders fine.
  3. wanted to mention that except not being able to customize colors of chart, everyhting else works fine.
  4. I'm trying to use a ChartCustomizer to set color of Pie chart sections. the problem i have is that i can't get to the dataset. datasert that i get by calling piePlot.getDataset() is empty. Code:<pieChart> <chart hyperlinkTarget="Self" customizerClass="jasper.ChartLabelCustomizer"> <reportElement x="0" y="0" width="555" height="300" style="chart"/> <box></box> <chartLegend textColor="#000000" backgroundColor="#FFFFFF" position="Left"> </chartLegend> </chart> <pieDataset> <dataset></dataset> <keyExpression><![CDATA[$F{source} + " - " + new java.text.DecimalFormat("##.#").format($F{clickPercentage}) + " %"]]></keyExpression> <valueExpression><![CDATA[$F{clickPercentage}]]></valueExpression> <labelExpression><![CDATA[$F{source}]]></labelExpression> </pieDataset> <piePlot isCircular="true" > <plot backcolor="#FFFFFF" orientation="Horizontal"></plot> </piePlot></pieChart>public class ChartLabelCustomizer extends JRAbstractChartCustomizer{ public void customize(JFreeChart chart, JRChart jasperChart) { // Check the type of plot Plot plot = chart.getPlot(); if (plot instanceof PiePlot) { PiePlot piePlot = (PiePlot) plot; piePlot.setMaximumLabelWidth(0.20); piePlot.setInsets(new RectangleInsets(UnitType.ABSOLUTE, 0.0, 0.0,1.0, 1.0)); piePlot.setLegendItemShape(new Rectangle2D.Double(1.0, 2.0, 30.0, 6.0)); RectangleInsets margin = chart.getLegend().getMargin(); chart.getLegend().setMargin(margin.getTop(), 20D, margin.getBottom(), margin.getRight()); PieDataset dataset = piePlot.getDataset(); System.out.println("Printing keys, count : " + dataset.getItemCount()); for (int i = 0; i < dataset.getItemCount(); i++) { } } }}
  5. Thanks Teodor, This how I addressed this requirement. As we don't want to have any hypelink in PDF exports, i extended JRPdfExporter and overloaded setHyperlinkInfo with a method with and empty body. Code:public class JRPdfExporterWithoutHyperlinks extends JRPdfExporter{ @Override protected void setHyperlinkInfo(Chunk chunk, JRPrintHyperlink link) { //do nothing, we don't want Hyperlinks in pdf }}
  6. I generate reports in HTML and PDF, there are some hyperlinks in the report which i want to render only in HTML and not in PDF. Is there any way that based on format, render or not render hyperlinks? Thanks!
  7. OK i found a solution for this: Create a calss that implements net.sf.jasperreports.engine.JRTemplate and setup styles in that class. (see ACMETemplate) include this class as a template element in your jrxml file :<template class="net.sf.jasperreports.engine.JRTemplate"><![CDATA[new acme.jasper.ACMETemplate()]]></template>doing this you can control style of all your reports in a single defenition class. Code:package acme.jasper;import java.awt.Color;import net.sf.jasperreports.engine.JRAlignment;import net.sf.jasperreports.engine.JRElement;import net.sf.jasperreports.engine.JRException;import net.sf.jasperreports.engine.JRSimpleTemplate;import net.sf.jasperreports.engine.design.JRDesignStyle;public class ACMETemplate extends JRSimpleTemplate{ public MarchexTemplate() throws JRException { super(); Color blue = new Color(123, 177, 208); JRDesignStyle defultStyle = new JRDesignStyle(); defultStyle.setName("defult"); defultStyle.setDefault(true); defultStyle.setFontName("Arial"); defultStyle.setFontSize(12); defultStyle.setVerticalAlignment(JRAlignment.VERTICAL_ALIGN_MIDDLE); defultStyle.setMode(JRElement.MODE_OPAQUE); addStyle(defultStyle); JRDesignStyle tableTitleStyle = new JRDesignStyle(); tableTitleStyle.setParentStyle(defultStyle); tableTitleStyle.setName("tableTitle"); tableTitleStyle.setBold(true); addStyle(tableTitleStyle); JRDesignStyle topHeaderStyle = new JRDesignStyle(); topHeaderStyle.setParentStyle(defultStyle); topHeaderStyle.setName("topHeader"); topHeaderStyle.setBold(true); topHeaderStyle.setBackcolor(blue); topHeaderStyle.getLineBox().setLeftPadding(5); topHeaderStyle.getLineBox().setRightPadding(5); addStyle(topHeaderStyle); JRDesignStyle cellStyle = new JRDesignStyle(); cellStyle.setParentStyle(defultStyle); cellStyle.setName("cell"); cellStyle.setHorizontalAlignment(JRAlignment.HORIZONTAL_ALIGN_RIGHT); cellStyle.getLineBox().setLeftPadding(5); cellStyle.getLineBox().setRightPadding(5); cellStyle.getLineBox().getTopPen().setLineColor(blue); cellStyle.getLineBox().getTopPen().setLineWidth(0); cellStyle.getLineBox().getLeftPen().setLineColor(blue); cellStyle.getLineBox().getLeftPen().setLineWidth(0.25F); cellStyle.getLineBox().getBottomPen().setLineColor(blue); cellStyle.getLineBox().getBottomPen().setLineWidth(0.25F); cellStyle.getLineBox().getRightPen().setLineColor(blue); cellStyle.getLineBox().getRightPen().setLineWidth(0.25F); addStyle(cellStyle); JRDesignStyle leftHeaderStyle = new JRDesignStyle(); leftHeaderStyle.setParentStyle(defultStyle); leftHeaderStyle.setName("leftHeader"); leftHeaderStyle.setHorizontalAlignment(JRAlignment.HORIZONTAL_ALIGN_LEFT); leftHeaderStyle.setBackcolor(Color.LIGHT_GRAY); leftHeaderStyle.getLineBox().setLeftPadding(5); addStyle(leftHeaderStyle); JRDesignStyle leftAlignCellStyle = new JRDesignStyle(); leftAlignCellStyle.setParentStyle(defultStyle); leftAlignCellStyle.setName("leftAlignCell"); leftAlignCellStyle.setHorizontalAlignment(JRAlignment.HORIZONTAL_ALIGN_LEFT); addStyle(leftAlignCellStyle); }}
  8. To eliminate duplication and provide consistance look and feel across all reports i've decided to remove style defenitions from .jrxml files and define them in java and pass them to JasperPrint at run time as JRParameter.REPORT_TEMPLATES parameter. reports can include sub reports. I've bean successfull to do this for the main report but havn't found a way pass these templates to sub reports. any suggestion?
  9. To eliminate duplication and provide consistance look and feel across all reports i've decided to remove style defenitions from .jrxml files and define them in java and pass them to JasperPrint at run time as JRParameter.REPORT_TEMPLATES parameter. reports can include sub reports. I've bean successfull to do this for the main report but havn't found a way pass these templates to sub reports. any suggestion?
  10. To eliminate duplication and provide consistance look and feel across all reports i've decided to remove style defenitions from .jrxml files and define them in java and pass them to JasperPrint at run time as JRParameter.REPORT_TEMPLATES parameter. reports can include sub reports. I've bean successfull to do this for the main report but havn't found a way pass these templates to sub reports. any suggestion?
×
×
  • Create New...