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

cbrownmacquarietelecom.co

Members
  • Posts

    11
  • Joined

  • Last visited

cbrownmacquarietelecom.co's Achievements

Apprentice

Apprentice (3/14)

  • Week One Done
  • One Month Later
  • One Year In
  • First Post Rare
  • Collaborator Rare

Recent Badges

0

Reputation

  1. Hi, I managed to get my report working eventually (using the settings given in my original query). I have a report book component for which the data source expression uses net.sf.jasperreports.engine.JREmptyDataSource; I think my scriptlet erroneously referenced this data source (hence the error "Cannot cast object 'net.sf.jasperreports.engine.JREmptyDataSource ..."). To fix this I introduced an intermediate sub-report in which I defined the data source I needed to use in the scriptlet, then, eventually, called a sub-report with the appropriate Scriplet class set. I hope this is useful. Cheers Chris
  2. Hi, I have used the JFreeChartScriptlet to generate a chart that uses the XYZDataset. For testing I've hardcoded the datasource (an XML file) but I need to hook the scriptlet up the report's datasource which is the content of a webservice response. Due to the number of data points it is impracticle to access the chart data via a number of fields. The $V{Chart} is in a subreport; the subreport's data source expression is: In the scriptlet I'm trying to access the data source as follows: When I preview the report I get the following exception: How do I reference an external data source from within a scriptlet?
  3. The answer to my question is create a report (that uses an image element) with an appropriate scriptlet class. Create a variable with class attribute set to net.sf.jasperreports.engine.JRRenderable. I used the afterReportInit() method where I set the variable using JCommonDrawableRenderer(). The chart uses a DateAxis that ranges between the first and last days of a month. I've tested the chart building code in a separate Java program and used the code in the scriptlet. The following statement "xAxis.setRange(end.getTime(), start.getTime());" works in my Java code but fails in the scriptlet with "net.sf.jasperreports.engine.JRException: java.lang.IllegalArgumentException: Requires 'lower' < 'upper'.". The relevant scriptlet code is as follows: public void afterReportInit() throws JRScriptletException { int year = 2016; int month = 1; int day = 1; Calendar[] dates = dateRange(year, month, day); Calendar start = dates[0]; Calendar end = dates[1]; XYZDataset dataset = createDataset(start, end); DateAxis xAxis = new DateAxis(); xAxis.setRange(start.getTime(), end.getTime()); xAxis.setLowerMargin(0.0); NumberAxis yAxis = new NumberAxis(); yAxis.setUpperMargin(0.0); yAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); XYBlockRenderer renderer = new XYBlockRenderer(); renderer.setBlockWidth(1000.0 * 60.0 * 60.0 * 24.0); renderer.setBlockHeight(0.5f); renderer.setBlockWidth(0.1f); XYPlot plot = new XYPlot(dataset, xAxis, yAxis, renderer); plot.setBackgroundPaint(Color.lightGray); plot.setRangeGridlinePaint(Color.white); plot.setAxisOffset(new RectangleInsets(5, 5, 5, 5)); JFreeChart chart = new JFreeChart(null, plot); chart.removeLegend(); chart.setBackgroundPaint(Color.white); ChartUtilities.applyCurrentTheme(chart); this.setVariableValue("Chart", new JCommonDrawableRenderer(chart)); } private static Calendar[] dateRange(int year, int month, int day) { Calendar start = new GregorianCalendar(year, month, day); start.set(Calendar.DAY_OF_MONTH, 1); start.set(Calendar.HOUR_OF_DAY, 0); start.set(Calendar.MINUTE, 0); start.set(Calendar.SECOND, 0); start.set(Calendar.MILLISECOND, 0); int numberOfDays = start.getActualMaximum(Calendar.DAY_OF_MONTH); Calendar end = (Calendar) start.clone(); end.set(Calendar.DAY_OF_MONTH, numberOfDays); end.set(Calendar.HOUR_OF_DAY, 23); end.set(Calendar.MINUTE, 59); end.set(Calendar.SECOND, 59); end.set(Calendar.MILLISECOND, 999); return new Calendar[] { start, end }; }[/code]What possible reason could there be for this inconsistency? On a different note, my scriplet are not picked up when I re-preview in Jasper Studio unless I restart the IDE which now entails having to exit. Can anyone tell me what happened to the restart menu option? I am running 6.2.0.final under Ubuntu 14.04.
  4. Hi, I'm trying to create a chart similar to the following: http://wwwisis2.isis.rl.ac.uk/DataAnalysis/jpowder/Images/XYZDataSet.png. The chart in question uses an XYZDataset, however the Jasper Reports API only refers to the Bubble chart. There is no mention of XYBlock or XYShape charts. To date I have used chart customisers to tweak charts where required but I'm wondering if I need to use a different approach in this instance. I've attempted to create a cusomiser for a bubble chart but need to work out how to override the default rendering of bubbles. I'm not sure if this is best use of my time. I have been reading documentation on rendering images using third party APIs and it looks like I should be able to create a chart of my choice using a scriptlet. Is a valid approach? Cheers
  5. The more I think about this, the more I think its un-achievable. I'd like to hear from anyone who can prove otherwise.
  6. Hi, I'm working with Studio version 6.2 to create a book report which, for the most part, is fine. Something I haven't been able to do is to control printing of a book part that consists of a text element (in the page header band) and 4 sub-report elements (each in a detail band). The book part should be printed if one (or more) sub reports return data. Each sub report uses its own data source. The data source for the book part is JREmptyDataSource(); Given the descriptions of the JREmptyDataSource() and "When No Data Type" I don't think I can use these to determine whether or not the book part should be printed. I've tried returning values from the sub reports and using a scriptlet to determine the total number of records returned to the main report. I haven't been able to use either to successfully acquire then use each sub report's REPORT_COUNT. Any advice on how to achieve the above would be much appreciated. Regards Chris
  7. Hi, I'm working with studio 6.1 and trying to generate a series of chart/table pairs. Each chart and table will use the same recordset. My first step is to come up with an XML structure that serves both purposes. Essentially I have a list of records; each record contains a few preamble nodes, followed by a list of data nodes. The snippet below captures what I'm currently working with. <data> <top_level>Blah</top_level> <records> <record> <preamble>Blah</preamble> <more_preamble>Blah</more_preamble> <dateset> <month>Jan</month> <data attrib="A">10</data> <data attrib="B">40</data> <data attrib="C">20</data> <data attrib="D">60</data> </dataset> <dateset> <month>Feb</month> <data attrib="A">30</data> <data attrib="B">60</data> <data attrib="C">80</data> <data attrib="D">10</data> </dataset> <dateset> <month>Mar</month> <data attrib="A">70</data> <data attrib="B">90</data> <data attrib="C">100</data> <data attrib="D">20</data> </dataset> </record> <record> <dateset> <month>Aug</month> <data attrib="A">90</data> <data attrib="B">40</data> <data attrib="C">70</data> <data attrib="D">20</data> </dataset> <dateset> <month>Sep</month> <data attrib="A">60</data> <data attrib="B">70</data> <data attrib="C">10</data> <data attrib="D">20</data> </dataset> <dateset> <month>Oct</month> <data attrib="A">20</data> <data attrib="B">10</data> <data attrib="C">0</data> <data attrib="D">60</data> </dataset> </record> </records></data>[/code]To start with I've created a subreport and placed a chart in the detail band. Setting the record node to /data/records/record would enable me to create one chart per record. The fields are defined as follows: preamble: preamblemore_preamble: more_preamblemonth: //dateset/monthtypeA: //dateset/data[@=A]typeB: //dateset/data[@=B]typeC: //dateset/data[@=C]typeD: //dateset/data[@=D][/code]I'm using a stacked bar chart with Series A, B, C, and D; Category is set to $F{month} and value set to $F{typeA}, $F{typeB},$F{typeC},$F{typeD} respectively. I have also tried .//dataset... which make no difference. What I get when I preview are 2 charts where each contains the first dateset from record 1 and the first dataset from record 2. Presumably, if I had a third record, it's first record would also be displayed. I have a couple of questions: 1. Is there a better XML structure I should be using? What I have is easy to read but possibly isn't optimal when it come to charts and tables. 2. Can anyone explain what the heck is going on with my current setup? I can't understand why the xpath expressions fail. Cheers Chris
  8. Hi, Given a range CSV data files where the field separator is the TAB character, how do you specify the Data Source Expression for several subreports? I need to override the default separator and set useFirstRowAsHeader to TRUE; I've yet to determine a sensible way of setting a couple of attributes. Also, the record format of data files varies. Is it possible to implement a general solution where specifics are defined in subreport parameters? I've looked at scriptlets and data adapter-related wiki entries. I've also tried extending JRCsvDataSource. I am new to Jasper Reports (using studio v6.1) and Java is not my first language, so I'd appreciate an explanation, i.e pros and cons, for each solution. Cheers Chris
×
×
  • Create New...