Thursday 25 March 2010

Generic Charting Concept

ASP Flexible Charting Solution

The challenge is to add a chart output option to a system containing many existing reports. This legacy system is written in classic asp, but it would be desirable to create the charts in asp.net so that the latest controls could be used.

Ideally, the solution should be reusable, so that many reports can have this facility added. If we can do this in a elegant way that allows the use of asp.net controls in a system running classic asp then we have achieved our goals.

New asp Function fnctSaveValuesForCharts

On classic asp system create a function with 3 arguments:
1) Recordset
2) Name of measure column
3) Name of description column

When the report is run for the first time, this new function should be called at the same time.

New asp.net aspx page.
The second part of the system will be a new asp.net page.
This will take three arguments:
  1. Segments (number of segments (n)),
  2. Style (Pie, Bar)
  3. Title (The title for the aspx page)

This will pick up the values and captions from the cookie saved by the classic asp page.
The top n-1 values will be displayed in bars or slices
The rest or the values that are not in the top n-1 will be summarised and displayed in a single bar/slice with the caption "Others"

For example, if the user chooses 5 slices, the pie chart will show the top 4 categories as individual slices, then all the other values will be summarised in the "Others" slice.
Having an "others" column/slice avoids cluttering up the chart with insignificant data.

The advantages of this overall approach are:
  • It avoids the need to run the same query a second time
  • Avoids need to transfer a complex object, such as a recordset, between asp version
  • The data required for the charting is saved in a simple form ready for use
  • The charting can easily be added to many pages. Changes to the look of the charts only need to be done in one place.
See this article on how to share session state information between asp versions: