Question : MS Access - dynamically/programaticall<wbr />y creating Pivot Charts using Office Chart component

Dear experts,  I urgently need of some help from someone who has experience programmatically creating Pivot Charts... I have been working on this for almost a week now searching for examples on line, reading through all of my books etc. but not making enough progress.   In addition, I'm hoping for some insight for whether I am taking a good approach to this.   I really need some guidance and/or insight from someone with more experience.

Here is what I'm trying to do:  

Dynamically create a line chart that displays time series of 2 different measures.    

- avg age of problems since enter date
- avg age of problems since transaction date.

X axis will show dates for time range and the values for the 2 measures just mentioned will be plotted for each day over the time series.

User specifies time range on a form - ie.3/29/1/06 - 6/1/06 and the program should generate a graph (either as a form within a report, or as a form that pops up in pivot chart view)

sample date:
DATE      AVG_OPEN_PROB_AGE_T      AVG_OPEN_PROB_AGE_E
3/29/2006       305                                           10
3/30/2006       305                                           10
3/31/2006       306                                           11
4/1/2006       307                                           12
4/3/2006       309                                           14
4/4/2006       310                                           15
4/5/2006       311                                           16
4/6/2006       140                                             7

Pseudocode:
- Dynamically create SQL String
- Open ADO Recordset and obtain data for chart and put into strings
- Open a new form
- add chartspace to form
- add series to chart
- add data to the series, specify categories and values

For some reason my code is not showing the dates properly on the x axis (there are large gaps - doesn't show daily), It appears that the points on the graph are possibly getting summed up?

If I do this manually by, the gap between dates and summed up values doesn't occur
- dropping the date field in the Category Field space
- dropping the other 2 fields in the Totals / detail space
Problem here is 1. It's not dynamic 2. there are too many dates ...... cluttering the x axis.

Any suggestions, help, or guidance will be greatly appreciated.   I also have code that I can share as needed....  Thanks in advance for any help you can provide on this!


Answer : MS Access - dynamically/programaticall<wbr />y creating Pivot Charts using Office Chart component

lorincha,

I see your point about MS-Chart being a dead end. It was like this from the very beginning, since Excel 4 or thereabout. The object model of MS-Chart is basically a port from Excel, explaining why all the constants are prefixed with "xl"... You can learn all there is to know about it by starting the macro recorder in Excel and creating / manipulating graphs. The exact same code will run for MS-Charts.

This means that the procedural model is really simple: create a query that will produce the series you want to plot and feed that to MS-Chart. You can either preformat your graph with all needed properties or even adjust them dynamically (again, record a macro in Excel doing just that and use the code as template).

Pivot tables and pivot charts, on the other hand, are extraordinarly complex. This is where I see a steep learning curve, btw. In typical MS fashion, you have an overload of properties, a highly redundant and misleading object model, impossible encapsulation of each and every branch, etc. You can guess that MS will want to sell you later on the "meta pivot manager", to help you create and maintain them.

At least, I don't see any recent resources on the topic. Not even on Pivot tables (on which pivot charts are based). Apparently, most programmers are staying well away from them, and I don't recall a single expert comment being made on this site about them...

The sad part is that the actual charting options of pivot charts are exactly those of MS-Chart. No more! Still no histograms, no mutiple axis, no surface plots, no error bars, no true 3D charts, no overlays, no isometric scales, no rotations, ... Basically the same toy for managers and other power point addicts. Only with more complexity...

Ah, well. The entry point for the data is, naturally, Me.PivotTable. Any actual data manipulation is done from there. For the Chart (appearance, type, formatting of axes and series, etc.), the entry point is Me.ChartSpace. Explore that tree in debug mode and get a glimpse...

As an example: change a marker on a line series to yellow:

Me.ChartSpace.Charts(0).SeriesCollection(0).Points(0).Interior.Color = vbYellow

In fact, the Charts(0) object seems about 99% compatible with MS-Charts, where you would go:

.Object.SeriesCollection(0).Points(0).Interior.Color = vbYellow

Anyway, good luck!
(°v°)
Random Solutions  
 
programming4us programming4us