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

matthew.harrison

Members
  • Posts

    4
  • Joined

  • Last visited

matthew.harrison's Achievements

  1. I ended up finding an answer for this in the end. If its of any use to people in the future, I created a chart customizer, which allowed me to define a property to define the legend labels: import java.util.Iterator;import org.jfree.chart.JFreeChart;import org.jfree.chart.LegendItem;import org.jfree.chart.LegendItemCollection;import org.jfree.chart.plot.CategoryPlot;import net.sf.jasperreports.engine.JRAbstractChartCustomizer;import net.sf.jasperreports.engine.JRChart;import net.sf.jasperreports.engine.JRPropertiesMap;/** * Provides customisation of the chart display that are not possible with JasperReport properties. */public class ChartCustomiser extends JRAbstractChartCustomizer { @Override public void customize(final JFreeChart chart, final JRChart jasperChart) { final String[] legendLabels = findLegendLabelProperty(jasperChart); if (legendLabels.length > 0 && chart.getPlot() instanceof CategoryPlot) { reorderLegendLabels(legendLabels, chart); } } private void reorderLegendLabels(final String[] legendLabels, final JFreeChart chart) { final LegendItemCollection newLegendItemCollection = new LegendItemCollection(); for (final String label : legendLabels) { @SuppressWarnings("unchecked") final Iterator existingLegendItemIterator = chart.getLegend().getSources()[0].getLegendItems().iterator(); while (existingLegendItemIterator.hasNext()) { final LegendItem item = existingLegendItemIterator.next(); if (item.getDescription().equals(label)) { newLegendItemCollection.add(item); break; } } } if (newLegendItemCollection.getItemCount() > 0) { ((CategoryPlot) chart.getPlot()).setFixedLegendItems(newLegendItemCollection); } } private String[] findLegendLabelProperty(final JRChart jasperChart) { final JRPropertiesMap pm = jasperChart.getPropertiesMap(); final String legend = pm.getProperty("LegendLabels"); if (legend != null && !legend.isEmpty()) { return legend.split("\|"); } return new String[0]; }}[/code]This does mean if any items are missed from the LegendLabels property they don't get displayed, but it works for me.Hope this may be of use to someone if they hit the same issue, cheers,Matt
  2. Hi, I've hit a bit of an issue, and am hopeful someone can give me some pointers on formatting my charts correctly. What I'm doinf is producing a stacked bar chart, which is fine. However the problem I'm having is that the Legend (showing the Series data) should be in a defined order. In the SQL I can define the order, but this is for the Category, and then the Series, so for example if I get data that looks like this (I think - this is just made up data): CategorySeriesValue125213228337Then when the graph is shown the Category is sorted fine, but the Legend (showing the Series), would look like [2, 1, 3] in this case I believe - i.e. in the order that they come in in the data. Is there a way to sort them in a customised way? I did try putting 'dummy' data into the data set, so that the first record would have the correct sort order for the Categories, which sort of worked, but this gets messy fast I think. So am I now looking at a customizer to get it sorted correctly? If so any pointers would be appreciated. Thanks in advance, Matt
  3. Hmm, ok. I had a little look at the HTML exporter, and made some changes so that when it found a new style it created a class, and added a style into the page, and then used that style further on in the page. This reduced my 138Mb report down to 73Mb - still too big for us, but anyway. What we've ended up doing is pointing the users to other renditions by default. The changes I made do seem to produce a large reduction in the HTML size (although I think to really cut it down you would need to do something more drastic to the page). Would it be something of interest for me to contribute back? (if so could you point me to the getting started point for contributions?) Cheers, Matt
  4. I've been using Jasper Reports 6.1.0 to produce reports, and its generally going quite well. One issue I've hit is that when we produce HTML reports with quite a few results the HTML page that gets generated is too big to open in IE (effectively). It will just about open in Chrome, but that's not the target here. I think the issue is that each cell in the report gets its own 'style=...' attribute. Whilst I can understand that this gives full control over the display in the report, in my case its making the HTML rather large - and the report layout in this case is a very simple grid. Is there any way that styles can be set externally (CSS), and/or the 'style=...' attribute can be suppressed? Or any ideas on how I might reduce the amount of style settings used? Thanks in advance, Matt
×
×
  • Create New...