Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Help me ................

0 views
Skip to first unread message

lavnaya

unread,
Apr 11, 2000, 3:00:00 AM4/11/00
to
Hi all
we are using the following code to generate a graph in the picture box, it
is taking 28 sec on a celeron 525, with 128 mb ram, this is an performance
issue,( we want to reduce the time to 5 to 10 secs)is there a way we can do
this. any help will be really appreciated.
thanks in advance
venkat

HERE
leftbound = 1,rightbound = 12456
item is a object
graphlist is a collection
piccentergaraph is a picture box

For count = leftbound to rightbound
Set item = GraphList(count)
' First quartile curve
With item
ypos = (.FirstQ - .median) / .median
If count <> leftBound Then
picCenterGraph.PSet (prevPartCount, prevFirst), colBorder
picCenterGraph.Line (prevPartCount, prevFirst)-(partCount,
xaxis - ypos), colBorder
picCenterGraph.PSet (partCount, xaxis - ypos), colBorder
End If
If leftBound = rightBound Then
picCenterGraph.Line (0.95, xaxis - ypos)-(1.05, xaxis - ypos),
colBorder
End If

prevFirst = xaxis - ypos
' Third quartile curve
ypos = (.thirdq - .median) / .median
If count <> leftBound Then
picCenterGraph.PSet (prevPartCount, prevThird), colBorder
picCenterGraph.Line (prevPartCount, prevThird)-(partCount,
xaxis - ypos), colBorder
picCenterGraph.PSet (partCount, xaxis - ypos), colBorder
End If
If leftBound = rightBound Then
picCenterGraph.Line (0.95, xaxis - ypos)-(1.05, xaxis - ypos),
colBorder
End If
prevThird = xaxis - ypos
prevPartCount = partCount
partCount = partCount + 1
End With

Next


Zima

unread,
Apr 11, 2000, 3:00:00 AM4/11/00
to
Have you tried MS Excel automation or 3rd party controls? They're usually
optimized for this kind of work and speed is usually not an issue. If you
have Excel, first thing I'd try is to try its graphing capabilities via
Automation. If you need more info on how-to let me know I'll be glad to
provide more details, else search MSDN or help for Automation and Excel.

Cheers, Adam

"lavnaya" <lavanyach...@yahoo.com> wrote in message
news:e5lftb8o$GA.315@cppssbbsa04...

lavnaya

unread,
Apr 11, 2000, 3:00:00 AM4/11/00
to
Adams

any further help will be really appreciated. some sample code will be
great.

thanks
venkat
Zima wrote in message ...

Zima

unread,
Apr 11, 2000, 3:00:00 AM4/11/00
to
Perhaps even an easier way would to be to use MSChart control. You can set
reverence to it via Components menu. It is "Microsoft Chart Control 6.0
(OLEDB)" - file name: mschrt20.ocx. The following sample code can be found
in MSDN:

Private Sub Command1_Click()

With MSChart1
' Displays a 3d chart with 8 columns and 8 rows
' data.
.chartType = VtChChartType3dBar
.ColumnCount = 8
.RowCount = 8
For Column = 1 To 8
For Row = 1 To 8
.Column = Column
.Row = Row
.Data = Row * 10
Next Row
Next Column
' Use the chart as the backdrop of the legend.
.ShowLegend = True
.SelectPart VtChPartTypePlot, index1, index2, _
index3, index4
.EditCopy
.SelectPart VtChPartTypeLegend, index1, _
index2, index3, index4
.EditPaste
End With

End Sub

NOTE: This code assumes you have MSChart1 object instanciated on the form
and a buttom Command1 with the above code. Also, since MSDN example does not
explicitly define variables, remove Option Explicit statment from the module
if you have your VB settings require var declaration.

Adam


"lavnaya" <lavanyach...@yahoo.com> wrote in message

news:OIxpBm8o$GA.87@cppssbbsa04...

Stephen Smith

unread,
Apr 14, 2000, 3:00:00 AM4/14/00
to
Hi lavnaya,

There are many ways you can speed up this code - basically by
stripping down everything possible inside the loop.

Firstly, it is drawing 2 points and 1 line for every point on the
graph, which is overdoing it. Graphics are by far the most
time-consuming operation (since, simplistically speaking, the
information needs sending to the graphics card; and if the picturebox
is visible, the monitor gets refreshed after every graphics
operation). Secondly, take all constants out of the loop. Also,
simplify the maths, so that "(.FirstQ - .median) / .median" becomes
".FirstQ / .median - 1"

Here is your code again, but heavily butchered. I'd wager this is 2
to 3 times faster already...

Other Ideas:

* If it is plotting only 1 pixel per line (is 12456 in pixels?), use
Pset instead of Line in the code below.

* Speed it up by another 20% using graphics API - SetPixel instead of
PSet, and LineTo/PolyLine instead of Line.

All of this may get it down to one or two seconds!

Steve.

leftbound = 1,rightbound = 12456
item is a object
graphlist is a collection
piccentergaraph is a picture box

' this will increase speed many many times
picCenterGraph.visible=false
picCenterGraph.autoredraw=true

forecolPrev=picCenterGraph.forecolor
picCenterGraph.forecolor=colBorder ' (don't ask 'Line' to set it every time)
if leftbound=rightbound then

' for speed in loops below, separate out this code

' First quartile curve
ypos = GraphList(leftbound).FirstQ / GraphList(leftbound).median - 1
picCenterGraph.Line (0.95, xaxis - ypos)-step (0.1, 0)

' Third quartile curve
ypos = GraphList(leftbound).thirdq / GraphList(leftbound).median - 1
picCenterGraph.Line (0.95, xaxis - ypos)-step(0.1, 0)

else

' to facilitate the speedy "Line -(x,y)", draw each graph separately

' First quartile curve
ypos = GraphList(leftbound).FirstQ / GraphList(leftbound).median - 1
picCenterGraph.pset (0, xaxis - ypos)' (position the graphics cursor)

For count = leftbound+1 to rightbound
ypos = GraphList(count).FirstQ / GraphList(count).median - 1
picCenterGraph.Line -(count - leftbound, xaxis - ypos)
Next

' Third quartile curve
ypos = GraphList(leftbound).thirdq / GraphList(leftbound).median - 1
picCenterGraph.pset (0, xaxis - ypos)' (position the graphics cursor)

For count = leftbound+1 to rightbound
ypos = GraphList(count).thirdq / GraphList(count).median - 1
picCenterGraph.Line -(count - leftbound, xaxis - ypos)
Next

endif
picCenterGraph.forecolor=forecolPrev

' refresh display
picCenterGraph.autoredraw=false
picCenterGraph.visible=true
picCenterGraph.refresh ' (this might not be necessary)

0 new messages