Update (2004-December-21):

In SmartGraph, there was a problem in labeling X and Y axes, now it has been solved.

Selection problem in demo project solved.

Name of output file changed to SmartGraph rather than Graph.

Introduction

In my recent projects, I needed to show some data in a 2D graph. This graph must have capability of zoom in, zoom out, and colorization. At first, I wrote some code directly in my VC project and the result was satisfactory, but I had to do it for any new project and it was time consuming. So, I thought of doing it as an ATL component so that it does all the things I need. This SmartGraph is what I want.

SmartGraph is written in VC++ .NET 2003 using ATL and has several good methods, events and properties that makes it something easy to use.

This SmartGraph is an ActiveX, so it can be used in any visual language that supports ActiveX, such as Visual C++, Visual Basic, C#, Delphi, ... It can resample its data more quickly by using SetData(.,.,.,true). It also can be viewed as Regular graph, Dot graph, or Bar graph by using SetPlotType(.).

How to use SmartGraph?

To use SmartGraph, you must do these steps:

Register SmartGraph using this command at command prompt: "regsvr32 <PATH>\Graph.dll", or only compile "Graph.sln".

Note: if you don’t have VC++ .NET, you can’t register Graph.dll unless you copy "msvcr71.dll" to your Windows directory. (This file is attached to this article.)

In your project, press right-click on your ToolBox and then "Add/Remove Item", then select "SmartGraph" from "COM Components" tab, now it must appear in your toolbox.

Now, only click on it and drag it to your dialog, now create a variable and use it:

trend1->SetData2(xdata,ydata,nLen,-25.0,100.0,-25.0,100.0,true); trend1->UpdateGraph(); trend1->Refresh(); }As result I got a straight line with a right end following the x and y data (as it should do), and left starting point with constant y value, and changing x value that behaves like y data of ending point (in this example oscilating around 0 value). In other words something like swinging lever...

xData and yData must be pointers to the start of data, for example if xData = int [10] and yData = int [10], then you must call setData with &xData, and &yData as parameters. I think in C# you must do this in a "fixed" block

First of all, let me say thank you for this handy control. It is just what I was looking for for one of my dialog-based MFC applications. But I am having some trouble integrating this with the application.

I have added this control to a property page but as soon as I click the tab for this particular property page, it disappears. The application and the other property pages work fine even after that. The constructor for the property page is called, but OnInitDialog is never called. It looks like the page receives a AfxSig_v_v_v signal and OnDestroy is called to process the signal. I have added the statements you have given in your article to the InitDialog function and I have also taken a look at the demo project.

Do you know what could be the problem here? Am I missing something very obvious? I am using Visual Studio .Net 2003 and the programming language is C/C++.

Phew...finally figured it out. I don't think anyone else will make such an obvious mistake, but in case they do, I hope this helps. I had forgotten to add AfxEnableControlContainer() call to the InitInstance() function for the application. Now everything works like a charm.

Hi, i work with VS2005.i try to open your dialog IDD_SMARTGRAPHDEMO_FORM with the resource viewer and i have this message:The activeX control "{A2919A75-B379-4BBD-8D95-15BEB3BAA140}" is not registered. Register the control and try again.

The ActiveX is graph.dll, you can find it in binary files. register it using the following command in Run menu: Regsvr32 <filepath\graph.dll>you must have some dlls to register it, they are included in binary files, I think.good luck

SetData takes two, "double %"s, an int and a bool. Could someone tell me what a "double %" is, I've never seen something that looks like this before. This may be a stupid question, but I've never seen a "double %" before.

Yeah, I looked at the source and found it's supposed to be a "double *", but for some reason I can't figure out, when I add the compiled component into my project visual studio claims it's a 'double %'.

I have the loop in my code ,in whitch i want to plot new data every time.i use SmartGraph, but the graph don't update every loop and show only initial data, i try to use below code, but i can't succeed.{............. SetData(xdata,ydata,t, true); ShowWindow(SW_SHOW); UpdateWindow(); m_myError1.UpdateGraph(); UpdateWindow();}

I have the loop in my code ,in whitch i want to plot new data every time.i use SmartGraph, but the graph don't update every loop and show only initial data, i try to use below code, but i can't succeed.{............. myPlotError->m_myError1.SetData(xdata,ydata,t, true); myPlotError->ShowWindow(SW_SHOW); myPlotError->UpdateWindow(); myPlotError->m_myError1.UpdateGraph(); myPlotError->UpdateWindow();}

I am new to VC. please help me out.I want to use SmartGraph.dll in my current project. I had registered dll file. but I do not know how to add the dll into my project. do I still need any .h and . lib file?

Hello,this component is an ActiveX. To use it, you must at first register it using "regsvr32", then right click on your dialog and select "insert ActiveX". A list of all activex controls, installed on your pc, will be appeared, now select SmartGraph(or Graph). it will appear on the dialog...finished!

Hi,Hossein:Thanks for your reply.It works now, but when I try to add a variable m_Graph to the IDC_SmartGraph through ClassWizard, the Developer Studio generate a C++ wrapper class for ActiveX Smartgraph automically. When I rebuild project, I get a lot of compile errors for undeclared identifier, such as, VIS_I4 DISPID_BACKCOLOR...

Hi again,I work with VC 2003, but to check this problem, I tried smartGraph on my friend PC which works with VC 6.0 (SP6), I do the same steps as wrote before. then I add smartgraph to my project and used ClassWizard to create a variable. I used some functions(SetTitle, SetData, UpdateGraph). The project compiled without any error and all things ok. The only think remained is that SP6 has been installed here and I hope if you install SP6, your problem will be answered.

Thanks very much for your reply.I solve the problem by new another project, but I do not know how to show smartgraph in view window of MDI. I add a variable m_graph in the myview.h, but I do not know how to make it visble?

hiIts a great program, I was looking for one just like this.i tried installing as per the steps you have suggested, and I am using Visual C++, but it did not worked.can you help me in installing and using the code.aslo i would like to know what kind of input data is it? and what format is it?

We are having chart control which does real time graphing. I need to include Zoomin Zoomout capabilities. I thought your code must be usefule. Would you please give me your email so that I can ask you in much detail.

My query is the chart control is in MFC, VC++ 7. Can I use this Smartgraph control developed using ATL in my ocx project code? If so how to do this?

Please help me

Please let me know if this is not possible and if I requred to post my qurey in this dicussion board itself.

I've contacted the author and it seems not to work in VB. This graph component needs some pointers which is not supported by VB. My suggestion was to make it an OCX to overcome this problem perhaps. Unfortunately, I did not receive his opinion about this.

* If I highlight an area in SmartGraphDemo, then change the graph type, the highlight is hidden. When I highlight again, the yellow area reappears and the new highlight is in blue. So I have blue, yellow, blue, yellow, blue bands on the screen. (graph.dll is version 1.2.1.1)

* Some comments in the (demo) SmartGraph.h file specifying the parameters/returns would be very useful.

* The SmartGraph.cpp/h files in the control source and the demo source have different uses. So maybe different names would avoid confusion.