In the last weeks I was struggling with the MSChart ActiveX component to integrate it into one of my projects. I’ll post here my results since I believe it is worth to take a look at it because it can reduce the development time if you are looking for one of the several chart types this OCX offers.
To use this control we need an OCX container. Since it has the needed functionality, I used the ATL71 for this purpose. As an alternative, a custom OCX container can be coded to avoid the ATL71.DLL dependency. Not a big challenge, but a few 100 lines of code more. If you are going for it, take a look at Japheth’s implementation of OCXContainer. It implements the barebones, but it is enough for most of the existing controls.

The MSChart implementation is done using ObjAsm32. The core object is a simple descendant of WinPrimer, but it embeds a COM event sink to catch notifications from the control. This sink is a container object that hosts an IDispatch interface that acts as a callback for the control events. The coded dispatch mechanism uses the build in event table used to dispatch WM_* messages. This way a clean implementation is achieved. I’m considering extending the table generation to all method types for a future OA32 release.
I coded all dispatch methods to perform no response actions. In a further step you can easily intercept them to modify the chart behaviour. If you activate one of the axes in the attached example, a popup dialog is shown to modify the scale values. This is done one level higher overriding the AxisLabelActivated method of the current object instance.

MSChart runs in runtime mode, therefore it doesn’t require an extra license. If you want to use it in design mode, you will require some special behaviour at the client side and a design time license. The main advantage is a property dialog to customize the control, but all features can also be accessed at runtime using the put_* and set_* methods.

There are tons of examples on how to customize the MSChart control, so I will not go further on this.

If you get in the supplied example the error message “MSChart can't initialize” then one of the needed DLLs or OCX are missing or installed incorrectly.



PS: thanks to Homer and Obivan for revising the code.
Posted on 2009-06-01 05:46:38 by Biterider