Teechart Drawing Control-3-improve drawing efficiency

Source: Internet
Author: User

Vs2010 use teechart plotting controls-one-import controls and Classes

Vs2010 use the teechart Drawing Control-2-draw a graph (line chart, column chart)

Teechart Drawing Control-3-improve drawing efficiency

Teechart is a very powerful control with strong drawing capabilities, which is unmatched by other controls. However, the problem is its drawing speed. In fact, teechart is still very fast, it's just that you haven't used its functions correctly all the time, which leads to the illusion that the drawing speed is slow.

The following describes the two main factors that affect the drawing speed.

1. When there are too many points, you do not need to draw all points (performance improvement is not great)

Teechart widget-as mentioned in one article, you can set to plot only some points. Setting Method


This option can increase the drawing speed to a certain extent. For more information, see the following example:

163840 random points. The result of canceling the draw all validity period. The addxy function takes 1092 milliseconds.



163840 random points. The result of canceling the draw all validity period. The addxy function takes 1217 milliseconds.



This effect is not obvious, but the display effect is obvious.


2. Use the drawing function to change the drawing speed.

The addxy function of teechart draws the slowest function, but many people use it. It may be a simple reason. I dedicated a program to test the efficiency of addxy and addarray functions, detection efficiency is almost 30 times lower


2.1addxy function:

The addxy function needs to be refreshed every time it is called, so the drawing speed is quite low.

The implementation of the interface drawing (addxy) button is as follows:

Randf is a function that generates random numbers. For details, see the source file,

M_npointnum is the int type data associated with the text editing box

Idc_static_t is the ID of the text tag.

VoidCteechartdlg: onbnclickedbuttondraw ()
{
CSeries chartspeed = (CSeries) m_chart.series (0 );
Updatedata (true );
If(M_npointnum <= 0)
{
MessageBox (_ T ("data points cannot be less than 0 "));
Return;
}
DWORDDwtimes, dwtimee;
CstringSTR (_ T (""));
UnsignedI (0 );
Double* Pdatax = NULL;
Double* Pdatay = NULL;
// Allocate memory
Pdatax = New Double[M_npointnum];
Pdatay = New Double[M_npointnum];
For(I = 0; I <( Unsigned) M_npointnum; I ++)
{
Pdatay [I] = randf (-20, 20 );
Pdatax [I] = I;
}
// Because time needs to be calculated, drawing is not implemented in the first for loop.

Dwtimes = gettickcount ();
Chartspeed. Clear ();
For(I = 0; I <(Unsigned) M_npointnum; I ++)
{
Chartspeed. addxy (pdatax [I], pdatay [I], null, 0 );
}
Dwtimee = gettickcount ();
Dwtimee-= dwtimes;
If(Pdatax)
{
Delete[] Pdatax;
}
If(Pdatay)
{
Delete[] Pdatay;
}
Str. Format (_ T ("Time consumed: % d ms"), dwtimee );
Setdlgitemtext (idc_static_t, STR );
}

In

For(I = 0; I <( Unsigned) M_npointnum; I ++)
{
Chartspeed. addxy (pdatax [I], pdatay [I], null, 0 );
}

Two timing operations are added up and down to calculate the drawing time.

Running time: it took about 6 seconds to run the program at 1638400 o'clock.



2.2 addarray Function


To verify addarray's speed,

Added a button:

The button still implements drawing, but the addarray function is used.

Using colesafearray for data storage

The implementation code is as follows:

VoidCteechartdlg: onbnclickedbuttondraw2 ()
{
CSeries chartspeed = (CSeries) m_chart.series (0 );
Updatedata (true );
If(M_npointnum <= 0)
{
MessageBox (_ T ("data points cannot be less than 0 "));
Return;
}
DWORDDwtimes, dwtimee;
CstringSTR (_ T (""));
LongI (0 );
DoubleVal;

Colesafearray xvalues;
Colesafearray yvalues;
DWORDPnumelements []
= {M_npointnum };
Xvalues. Create (vt_r8, 1, pnumelements );
Yvalues. Create (vt_r8, 1, pnumelements );
For(I = 0; I <m_npointnum; I ++)
{
Val = I;
Xvalues. putelement (& I,
& Val );
Val = randf (-20, 20 );
Yvalues. putelement (& I,
& Val );
};
// Because time needs to be calculated, drawing is not implemented in the first for loop.
Dwtimes = gettickcount ();
Chartspeed. Clear ();
Chartspeed. addarray (m_npointnum, yvalues, xvalues );
Dwtimee = gettickcount ();
Dwtimee-= dwtimes;

Str. Format (_ T ("Time consumed: % d ms"), dwtimee );
Setdlgitemtext (idc_static_t, STR );
}

What is the effect?

View chart


Faster than 30 times, completed instantly at 1638400 points


In general, our data is often saved using double arrays and seldom uses colesafearray. Therefore, for convenience, you can write a function to facilitate drawing.

As follows:

VoidDrawline ( Double* PX, Double*
PY, LongNnum)
{
Colesafearray xvalues;
Colesafearray yvalues;
LongI (0 );
DWORDWlength
= Nnum;
Xvalues. Create (vt_r8, 1,
& Wlength );
Yvalues. Create (vt_r8, 1,
& Wlength );

For(I = 0; I <nnum; I ++)
{
Xvalues. putelement (& I, PX + I );
Yvalues. putelement (& I, Py + I );
}
CSeries chart = (CSeries) m_chart.series (0 );
Chart. Clear ();
Chart. addarray (nnum, yvalues, xvalues );
}

You only need to pass in the first address and length of the array during the call.


Teechart drawing controls cracked version: http://download.csdn.net/detail/czyt1988/4201107

Engineering Sample Code: http://download.csdn.net/detail/czyt1988/4201505


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.