Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Slow using Chartdata 1

Status
Not open for further replies.

N1GHTEYES

Technical User
Jun 18, 2004
771
0
0
GB
I am using an MSChart to display a single X,Y series and it seems to be ridiculously slow. I have the data in a 2 * n array (X values and Y values). n varies, but is around 25,000.

Creating and populating the array, then bunging it into a variant is fast enough, but when I execute the line

chrt.chartdata=pixvals

(where pixvals is the variant holding the 2d array which contains the data)

it takes about 8 seconds to complete. Huh?

Does anyone have any idea why this might be soooo ssslllloooowww? Are there any simple steps to fix it?


Any ideas appreciated.

Tony
 
I presume that this is the MSChart that ships with VB6? Prepare to be disappointed: it really isn't very good with large numbers of data points ...
 

Just a shot in the dark, but....
Every time I have problems with data showing slow in my controls, I check if there is something like .Redraw of .Refresh I can play with. Works for MSFlexGrid (set Redraw to False, populate grid, set Redraw to True), it may work with MSChart....

Just a guess since I don't use MSChart.

Have fun.

---- Andy
 
strongm: yep - 'fraid so.
Andy: I hardly ever use MSChart, so I'm not overly familiar with it's methods. Sounds like a good idea though if it is an option. I'll give it a bash. Thanks for the idea.

Tony
 
OK - I just had a quick browse. The property required seems to be .Repaint. Setting this to false is supposed to stop it updating with changes to the data. So I tried it.

No joy unfortunately. The line

.chartdata = pixvals

still takes about 8s to execute.

Grrr, arrggg!

Thanks for the suggestion anyway Andy. It sounded like a good idea.

I'll post a solution if I find a way of making it work properly.

Tony
 
Never used MSChart myself. I suppose the chart control has to process and store a lot of redundant data for displaying the chart. This is because you have some 25,000 data points, whereas the number of visible points (or pixels) on the chart will not be more than 1000, may be even less.

I suggest you reduce the number of data points to some manageable size by averaging the values within intervals, which you can do easily within VB6 and then pass the reduced data to MSChart, which it can handle easily.

If you want to show a simple line graph or bar graph, then you can even use VB6 drawing methods to plot the graph yourself, instead of using Chart control. It will require more coding, but will be even more faster and also avoid dependency on chart control.
 
Hypetia, thanks for the suggestion, but averaging per se won't work. The signal i'm displaying has a very few, very sharp peaks in it, and the value of the peaks, as well as their timing is mainly (but not only) what I want to show. I think I heard somewhere that the chart processes captured such extremes when displaying data and took them into account when drawing the chart, rather than simply averaging them internally.

However, it might be worthwhile splitting the data into a number of points equal to half the number of pixels displayed, then capturing the max and min in each section and displaying those values.

I'm still puzzled though - what can the chart be doing with the data which takes so long for so few points?

As for drawing it myself, well, yes, I'd considered that too, but this was meant to be a quick 'n' dirty look at some data, whereas it is starting to look more like a significant coding exercise.

Tony
 
>So few points

25000 is not a few points for MSChart, I'm afraid.
 
Can you show your relevant code, along with sample data, and output displayed on the chart?

There are some GDI functions in Win32 API, like Polyline, which might draw the entire graph in a single function call and it will take just a fraction of a second.
 
It turns out I was working with duff info. I've just started on a new task and wanted to display some of the data I would be working with in a convenient way to get a handle on what processing would be useful. The guy from whom I got the heads-up pointed me at some files which led to the above requirement.

Now it turns out, from somebody who had previously worked on the topic in greater depth, that the files I had been given have been superceded and the new format is completely different. I think that with the new files, the problem goes away.

However, thanks for the suggestions. I may still need to revist this later in which case I'll perhaps investigate polyline. Can you suggest a good information source, I might not find merely by googling?

strongm: re size - OK, I understand 25000 may be a lot for MSChart. What puzzled me is why. Basically, it does what Hypertia was suggesting - converts data values to pixel positions & displays the pixels. So why does it need so long to do that with just 25000 points? My puzzlement was because it just seems unecessarily slow.

Tony

 
>Can you suggest a good information source

See the documentation of Polyline function.

Also see this simple example, for drawing a graph. The code draws a high frequency carrier sine wave amplitude modulated by a low frequency signal, which is also a sine wave. First portion of the code just generates the x,y points and fills them in an array. Polyline function renders them on screen.
___
[tt]
Option Explicit
Private Declare Function Polyline Lib "gdi32" (ByVal hdc As Long, lpPoint As POINTAPI, ByVal nCount As Long) As Long
Private Type POINTAPI
x As Long
y As Long
End Type

Private Sub Form_Load()
WindowState = vbMaximized
ScaleMode = vbPixels
Show
'compose x,y data points
ReDim pt(ScaleWidth) As POINTAPI
Dim N As Long, H As Long, F As Single
H = ScaleHeight
For N = 0 To UBound(pt)
pt(N).x = N
F = Sin(N / 4) * Sin(N / 100)
pt(N).y = (1 / 2 - F / 3) * H
Next
'draw the waveform
AutoRedraw = True
Polyline hdc, pt(0), UBound(pt)
End Sub[/tt]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top