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

bklawans

Members
  • Posts

    122
  • 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

Posts posted by bklawans

  1. I just had to do that for a client, but they own the code so I can't post it.  I can tell you what I did though.

     

    Basically, you have to create a time based stacked area chart, then change the type of the x-axis to a time period axis.  This involves writing a chart customizer that makes some pretty big changes to the underlying JFreeChart.  It might be possible to do this via the new component or chart theme API in 3.1, but I was working with the 3.0.

     

    You want the area chart to be time based, so you have to author the report using a time series chart.  Don't worry that a time series chart in JasperReports is a line chart, as your customizer will change it.  This way your customizer gets a nice time based data set, and you can set the usual timePeriodExpression in the jrxml.

     

    The first thing your customizer has to do is convert the data set - JFreeChart requires a TimeTableXYDataset for stacked area charts, and JasperReports will have created the chart using a TimeSeriesCollection.  You can get the TimeSeriesCollection by calling chart.getPlot().getDataset() on the chart passed in to the customizer.  You create a new TimeTableXYDataset.  Then for each series in the original dataset loop through all the items in the series.  Add a new entry to your dataset using the period, value and key of the original item.

     

    Set the dataset in the chart's plot to the one you just created.  Create a StackedXYAreaRender2, and set that in the plot.  To avoid some JFreeChart issues set the plot's dataset rendering order and series rendering order to FORWARD.

     

    Finally, create a PeriodAxis, set the date intervals as appropriate for you chart, and then set that as the domain axis in the plot.

     

    I strongly recommend getting the JFreeChart documentation before trying this.  Its tricky, but when done you get a chart like the one attached.  It contains 30 days worth of data collected hourly, and the date axis is still readable.



    Post Edited by Barry Klawans at 12/19/08 20:05
  2. Do you want the nulls in the chart but with a different label, or do you want them filtered out? If you want to filter them out completely but can't do it in the query, use the filterExpression to skip rows that are null. The expression can be "new Boolean($F{field} == null)". In iReport there is a button on the query screen that lets you set the filter.
  3. Charts need a numeric value for the y-axis, otherwise the charting engine doesn't know how to space the values out. Do you want the y axis to reflect the duration, or the actual time? If its the duration, just plot the timestamp.

     

    From your first question I'm guessing this isn't what you want to do. If you want the labels on the y-axis to be dates, you can plot the values using the numeric timestamp you have, but format the axis labels as Dates. JasperReports supports setting a valueAxisLabelExpression, so you could set that to be "new Date($F{timestamp})" so the conversion to the date is only done for the axis labels. I can't remember where to set that in iReport.

     

    The drawback to this approach is that every distinct time value will have a different axis point - you are including the date and time. If you only want the chart axis to include dates, you may need to create a chart customizer that creates the axis labels manually.

  4. Its on JasperForge. Try http://jasperforge.org/plugins/project/project_home.php?group_id=173 It looks like the release packages and wiki content got confused during the recent JasperForge migration - the wiki content is for a different project... You should be able to access the source repository and anonymously check out the source to build.

     

    I've started work on a significantly improved version, and have the core JasperReports part all working, but I'm having trouble getting the iReport plugin to work with iReport 3.1.

     

    -Barry

  5. You need to convert the numeric field with the number of seconds to a Date field before you can use it with a time axis.  How to do this depends on what the numeric field actually means.  I recently finished an implementation for a client where they stored times in the database as number of milliseconds since January 1, 1970.  (This is a common Unix timestamp.)  That happens to be the way Java Dates work, so I declared a Variable in the report with the value "new Date($F{timestamp})" and then used the variable in the chart.

    There are a couple of things to consider when converting:

    • What does the time "0" mean in your database? You may need to add/subtract an offset to get to the Java base.
    • What is the resolution?  Seconds, milliseconds, something else?  You may need to scale to get to the Java value.
    • Time Zones?  At my clients site, all times were stored in UTC, so I didn't need to worry about time zones.  You may have to.

    -Barry

  6. frblusso writes

    As we do not use Net BEan (we use IBM software developpment platform with RSA to develop our web applications), I have chosen to download 3.0.0 version of ireport.

    I think there is  a bit of confustion here - the NetBeans version is available using the rich client platform, which means it is a stand alone application that happens to use the NetBeans framework, not a plug in.  You download and install it and the user is not aware of the fact that it is based on NetBeans, at least until they go to the preferences pane.

    -Barry

  7. There is also a project here on JasperForge that allows you to run an Oracle stored procedure directly inside JasperReports.  Its a bit old and doesn't include iReport support, but I've started work on a new version that will support iReport 3.1, once I figure out how to get plugins working in the the NetBeans version of iReport.

     

    -Barry Klawans

  8. Another possible approach is to do it in the query, if your datasource is SQL.

    Try something like

    SELECT "Answered" as type, num_answered as value from ...

    UNION

    SELECT "Not Answered" as type, num_not_answered as value from ...

     

    then you will get two rows, one with  the answered data, one with the unanswered data.

     

    -Barry

  9. $P!{} is a literal string substitution, while $P{} tries to use any built it parametrization support available by the data source. For example, if the data source is a JDBC connection, all the $P{} parameters are treated as IN parameters in a java.sql.PreparedStatement. This means only values can be parameterized. There are times where you want the query to include things that aren't valid JDBC parameters, such as an order by clause. In this case you have to use the $P!{} syntax.

     

    As an example, consider the SQL statement

     

    SELECT a, b, c
    FROM some_table
    WHERE b > $P{filterParam}
    ORDER BY $P!{orderParam}

     

    In this case the value in the WHERE clause should use $P, because it can be optimized by the JDBC driver. The ORDER BY clause can not be parameterized in a PreparedStatement, so we use the literal substitution form instead.

     

    Think of it this way - all parameter values using "$P!" are processed by JasperReports, and the resulting string is passed to the data source driver, that then handles the "$P" parameters.

     

    -Barry

  10. One possibility is to manually create a new dataset that uses those three values. The CSV or XML data sources are pretty good for this. For example, you can create a new Variable with a value of "$P{param1}n$P{param2}n$P{param3}".

     

    Set the pie chart to use its own dataset. In the pie's dataset, set the dataSourceExpression to

    Code:
    new JRCsvDataSource(new StringReader($V{yourVariable}))

     

    and see if that works. You will have to use a field called "COLUMN_0" as the name of the value.

     

    -Barry

  11. Hi Betty,

     

    That's an area of JFreeChart I haven't played around with, but the samples included with JFreeChart show stacked bars with the values displayed inside each segment of the bar, so it must be possible.

     

    Once you get it working, please post what you did hear so other people can benefit from it.

     

    Thanks,

    Barry

  12. Sounds like you are making progress, believe it or not. I'm guessing the 700+ pages are blank, right? They are the contents of the detail band, rendered for each row. Even when you haven't dragged anything into the detail band it still has a height.

     

    My guesses:

    1) Set the detail band height to 0. You can either drag the bottom light line in iReport that marks the end of the detail band up until it disappears, or right click in the band, select "Band Properties" and set the height to 0 in the dialog that pops up.

     

    2) It sounds like you only have one group for some reason. Double check your group expression is something that will change when you want it to. If you expression is something constant then every row will be in the same group. One good test is to put the expression in a field in the group header and footer, so you can see all the groups being processed.

     

    Once you get rid of the empty detail band and get the groups right we can take a look at the chart.

     

    -Barry

  13. You need to do more than call setSeriesItemLabelsVisibile - you need to add a label generator the chart's CategoryItemRenderer. Then call setItemLabelsVisible(true) on the renderer to see the labels.

     

    Teodor is right - get a copy of the JFreeChart Developers docs for detailed documentation and sample code.

     

    -Barry

  14. What do you want to the chart to show? Looking at the report you have time, host and cpu usage, and you have two possible axis. Do you want a different line per host, showing CPU usage over time? A chart per host?

     

    The current report you attached has the chart in the detail band. The detail band gets formatted once per row in the data, so in your case you get one chart per row, showing the data for that row.

     

    If you want one chart per host, you need to create a group for the host, and put the chart in the group footer. To do this, you will need to

     

    Create the group. Set the group expression to $F{host}

    Order the data by host by adding "order by hst.host" to your query

    Move the chart from the detail band to the group footer

    Set the chart's evaluation time to "Group" and set the group field to the name of your host group

    [/ol]

     

    -Barry

  15. Hmm, some time back I wrote a query executer available here on JasperForge that allows you to call PL/SQL stored procedures that return a cursor. It really needs to be updated - its from the dawn of query executers and has a lot of warts. It might be time to dust it off, and add function support at the same time. I'll look over the code in the next few weeks and see what it would take to do it right.

     

    -Barry

  16. For people like me who find the history of the tech industry interesting:

     

    Helvetica has been a popular font since the mid 1950s, way before the digital publishing age. It was one of the four fonts originally licensed by Adobe and included in all PostScript devices, so every publisher could count on it being available. The drawback to Helvetica is that it is owned by Linotype, and anybody distributing it has to pay royalties.

     

    One of Linotypes competitors, Monotype, created a font called Arial that used the same font metrics as Helvetica, and sold it at a much lower price. The differences between the two are subtle, and the idea was that replacing Helvetica with Arial at print time would preserve the layout of the document. Unfortunately, over the years, the fonts have evolved to where replacing Arial with Helvetica is not always safe.

     

    Microsoft licensed Arial for inclusion in Windows, and it as become the standard Windows font.

     

    -Barry

  17. What do you want the chart to show?

     

    The biggest problem is you are using $F{YEAR} as the series expression, but in you data the YEAR field is actually a date, not a year. This means every date in the database creates a new series, which is its own line.

     

    Ask yourself what do you want the X and Y axises to show. The X axis is the category, the Y axis is the value. If you want more than one data point at each X axis point, use multiple series.

     

    Given your data, what you want to display isn't obvious. Is it the value of nomesgsent and nouserreg by date? Or by company?

     

    -Barry

  18. Try creating a categoryDataset with

     

    Code:

    <categorySeries>
    <seriesExpression>"This Week"</seriesExpression>
    <categoryExpression>$F{IP}</categoryExpression>
    <valueExpression>$F{this_week}</valueExpression>
    </categorySeries>
    <categorySeries>
    <seriesExpression>"Last Week"</seriesExpression>
    <categoryExpression>$F{IP}</categoryExpression>
    <valueExpression>$F{last_week}</valueExpression>
    </categorySeries>

     

    The seriesExpression indicates the name of the series for a data point. The categoryExpression produces the x axis value, and the valueExpression produces the y axis value.

     

    -Barry

  19. Mark, are you trying to create a bar chart with two bars per year, one for high and one for low, or are you trying to create a single bar that shows both high and low for a year.

     

    If the former, you should be able to create a bar chart with a single category (the year) and two series, one for high and one for low. For fun, make it a stacked bar chart so the low is always in front of the high.

     

    If you want a chart where the low is the start of the bar and the high is the end of the bar, you will need to use a chart customizer and change the bar renderer, as greylimbo says.

     

    -Barry

  20. It looks like you set up your chart so that every data point is being treated as a separate series instead of different points on the same line. As a result, you get a bunch of lines that only contain one point.

     

    Check your data series for the chart. If you only want one line, set the seriesExpression for the categorySeries to a constant - some string that defines what it is showing. Then make sure the valueExpression actually has the value you want plotted. (Notice how the legend shows a date for each entry in the chart? That means it thinks each data point is its own series.)

     

    That should get you one line with a meaningful name in the legend. Then you can play around with settings like labelRotation, etc to get the chart to look nicer.

     

    -Barry

×
×
  • Create New...