16 November 2005
Crystal Reports: displaying a graph of the most recent data
I had to create a report in Crystal Reports--containing graphs of historical data within subgroups of users--that ended up being more complex that I had expected. Much of the information comes from the Crystal Reports Knowledge Base article C2011945 with little else available on the Web. Here are some notes using CR10:
Although the data was based on several joined tables, the basic problem can be simplified to a hypothetical table containing UserID, DataDate, DataName, and DataValue. The report needs to group by UserIDs and then to graph DataValues for the most recent 10 DataDates for each UserID. Ideally, the report will show each UserID's recent value trend, reading from left to right.
- Create a report and group by UserID,
- Select Report > Record Sort Expert... and sort by DataDate ascending,
- Select Insert > Chart...
- On the Type tab, select Chart type > "Line,"
- On the Data tab, select Placement > "For each UserID." This show one chart per UserID,
- Select Layout > Advanced,
- Move the DataName field to the "On change of" list. This is the source of our X axis values,
- Move the DataDate and DataValue fields to the "Show value(s)" list. These are the source of our Y axis values,
- Click the Order button and specify "in original order." This allows us to take the report order (specified above), but display the DataName values for the X axis,
- Click the TopN... button and sort using a Top N of 10 based on the DataDate field. The DataDate field must be included in the chart to use the TopN feature
The interesting aspect is that the sorting on DataDate must be specified in the report so that we can use the values of DataName for the X axis.
The report is configured at this point but contains two unpleasant problems. First, the DataDate values are displayed on the chart even though we only want the DataValue values. DataDate must be included in order to find the Top N. The Knowledge Base article gets around this by creating a report with only one chart and hiding the date plot points. This is achieved from a context menu item found in the preview mode. Because my report contains a variable number of dynamic charts, I can't hide the values using that technique. Instead, I took advantage of the fact that the data ranges for DataDate and DataValue are very different. I limited the chart's range to cover only the range of relevant values. This left an ugly but acceptable spurious chart line across the top border.
The second problem is that the plotted values are in reverse order across the X axis. Instead of plotting the most current date to the right, it plots it to the left. I tried many combinations of sorting (descending + Bottom N) without success.
I may-or-may-not have hit the limits of the Crystal Reports charts, but at least the results were "good enough" (never a phrase that instills pride) to ship.
- Techniques after using Swift for a month posted by sstrader on 26 August 2015 at 11:41:51 PM
- Some thoughts on Ruby after finishing a week (minus one day) of training posted by sstrader on 15 December 2011 at 8:59:30 PM
- Links on the singleton pattern posted by sstrader on 9 December 2011 at 9:19:50 AM
- Phonebot posted by sstrader on 29 October 2011 at 6:37:05 PM
- The labeled break in Java posted by sstrader on 4 September 2011 at 11:27:56 AM