
Home |
|
PegLineChart
|

Examples |

Index |
|
 |
|
|
 |
|
Overview |
Derived from class
PegChart
|
 |
|
The PegLineChart class provides a simple, single line,
two dimensional chart for plotting one data variable as a function of another.
The chart is drawn as a series of straight line segments joining the data
points. The chart has all of the characteristics provided by the
PegChart base class from which it is derived.
The PegLineChart class maintains a linked list of
the data points which make up the line chart. The data points are
joined by straight line segments. The line segments are drawn
from point to point in the order in which the data points appear
in the list.
Each data point is recorded in its own PegChartPoint structure
maintained by the PegLineChart class. These private structures
are used to identify data points and control their position
on the screen. The pointer to such a data point structure is called a
data point handle. Your application will have access to these
handles as you add, insert or remove the data points which form your
line chart.
 |
To use the PegLineChart class or its derivatives,
your KwikPeg configuration must have the following option enabled: |
| |
Drawing: Charts |
|
|
 |
 |
|
PegMultiLineChart
PegStripChart
The PegLineChart class supports
the following extended style flags:
CS_AUTOSIZE |
If this flag is set, the chart will always take up the
entire mClient region of its parent.
When the parent is resized or moved, the PegChart
object also resizes itself appropriately. |
CS_DRAWXGRID |
Draw grid lines along the X axis in the chart region. |
CS_DRAWYGRID |
Draw grid lines along the Y axis in the chart region. |
CS_DRAWXTICS |
Draw tick marks along the X axis at the specified intervals. |
CS_DRAWYTICS |
Draw tick marks along the Y axis at the specified intervals. |
CS_DRAWXLABELS |
Draw incremental value labels along the X axis below the chart.
The label values are based on the minimum and maximum possible
values of X. |
CS_DRAWYLABELS |
Draw incremental value labels along the Y axis to the left of the chart.
The label values are based on the minimum and maximum possible
values of Y. |
CS_DUALYLABELS |
Draw Y axis value labels along both the left and right
edges of the chart.
This style flag is ignored if the CS_DRAWYLABELS style flag
is not also set. |
CS_DUALYTICS |
Draw Y axis tick marks along both the left and right
edges of the chart.
This style flag is ignored if the CS_DRAWYTICS style flag
is not also set. |
CS_DRAWLINEFILL |
Fill the area between the trace lines and the (x,y=0) axis
with the currently specified fill color. |
CS_XAXISONZEROY |
Draw the X axis along the Y=0 axis instead of below the chart.
This style flag is ignored if the CS_DRAWXTICS style flag
is not also set. |
Constructors:
 |
 |
PegLineChart(const PegRect &Rect,
|
| |

LONG lMinX, LONG lMaxX,
|
| |

LONG lMinY, LONG lMaxY,
|
| |

WORD wXMajorScale = 0,
|
| |

WORD wYMajorScale = 0)
|
This constructor creates a single line chart
in the rectangle specified by parameter Rect.
If style flag CS_AUTOSIZE is to be used
(see function SetExStyle()), you may want to draw the chart
in the parent's mClient rectangle.
Parameters lMinX and lMaxX specify the
minimum and maximum X (horizontal) values. Parameters lMinY and
lMaxY specify the minimum and maximum Y (vertical) values.
Data points which lie outside these ranges, although not rejected, will not
be viewable in the chart rectangle.
Parameters wXMajorScale and wYMajorScale define
the intervals along the X and Y axes respectively at which major tick marks
will be drawn. Of course, tick marks are only drawn if the object's
CS_DRAWXTICS or CS_DRAWYTICS extended style
flag is set.
For example, if the minimum Y value
is -100, the maximum Y value is 900, the Y scale is 100 and
the CS_DRAWYTICS extended style flag is set, then tick marks
will be drawn on the Y axis at intervals of 100 starting at -100 and ending
at 900. Consequently, there will be 11 tick marks drawn on the Y axis.
If the CS_DRAWYGRID extended style flag is also set,
horizontal grid lines will also be drawn at the same tick mark intervals.
The interval at which axis label values are drawn is independent of
the tick mark/grid line scaling interval. Hence, tick marks might appear
at intervals of 100 with the axis values labeled at intervals of 200.
Public Functions:
 |
 |
PegChartPoint *AddPoint(
|
| |

LONG lX, LONG lY)
|
This function adds a new data point (lX,lY)
to the end of the data point list maintained by the line chart.
The function returns a data point handle which the chart
will use to identify the new data point and control
its position on the screen.
Rarely will there be a need for you to use the handle.
Use this procedure to add data points to the line chart in the order
in which you want the line segments drawn. Each data point added using this
function will be joined by a straight line segment to the data point
previously at the end of the data point list.
In most cases, data points should be added such that the X values are
monotonically increasing.
 |
 |
virtual void Draw(void)
|
The PegLineChart class overrides
the Draw() function to draw the straight line segments
that join each data point to make up the line chart.
 |
 |
PegChartPoint *GetFirstPoint(void) const
|
This function returns the data point handle for
the first data point of the line chart.
 |
 |
COLORVAL GetLineColor(void) const
|
This function returns the KwikPeg
COLORVAL value which defines the color of the line segments.
 |
 |
PegChartPoint *InsertPoint(
|
| |

PegChartPoint *pPoint,
|
| |

LONG lX, LONG lY)
|
This function inserts a new data point (lX,lY)
into the data point list maintained by the line chart.
The data point is inserted following the data point referenced
by the handle pPoint.
The function returns a new data point handle which the chart
will use to identify the new data point and control
its position on the screen.
 |
 |
virtual SIGNED Message(const PegMessage &Mesg)
|
The PegLineChart class overrides
the Message() function to recalculate the chart location
or layout when its parent is moved or resized.
 |
 |
void RecalcLine(void)
|
This function recalculates the screen coordinates for every data
point in the line chart.
This function is used privately by this chart class.
 |
 |
virtual void RecalcSize(
|
| |

const PegRect &NewRect,
|
| |

BOOL bRedraw = TRUE)
|
The PegLineChart class overrides
the RecalcSize() function to adjust the
line chart's location and size
as specified by the rectangle NewRect.
This function is used privately to redraw the line chart
if it is moved or resized.
The function uses the Resize() function to
update the screen coordinates of all the line data points.
If the bRedraw flag is TRUE,
the chart is redrawn.
 |
 |
PegChartPoint *RemovePoint(PegChartPoint *pPoint)
|
This function removes the data point referenced
by the handle pPoint from the line chart.
The function returns the handle of the data point which preceded
the removed data point. The function returns NULL
if the removed data point was at the head of the line chart data
point list.
 |
 |
void ResetLine(void)
|
This function removes all data points, if any, from the line chart.
All data point handles in your possession will be invalid after this
function is called.
 |
 |
virtual void Resize(PegRect NewRect)
|
The PegLineChart class overrides
the Resize() function to adjust the line chart's
location and size as specified by the rectangle NewRect.
The function calls the PegChart base class
RecalcLayout() function
but inhibits redrawing of the chart.
Function RecalcLine() is then used to reposition
all line data points within the revised chart.
This function is used privately by this chart class.
 |
 |
COLORVAL SetLineColor(COLORVAL Color)
|
This function sets the color to be used for drawing line segments
to the color defined by the COLORVAL value referenced
by Color.
The function returns the color that was previously being used
to draw chart lines.
The following code fragment illustrates the use of a
PegLineChart object to generate the line chart
pictured below.
PegRect Rect;
Rect.Set(20, 20, 600, 440);
PegLineChart *pLineChart =
new PegLineChart(Rect, 0, 1000, 0, 1000, 100, 100);
pLineChart->SetXLabelScale(200);
pLineChart->SetExStyle(
CS_DRAWXTICS | CS_DRAWYTICS |
CS_DRAWXGRID | CS_DRAWYGRID | CS_AUTOSIZE |
CS_DRAWYLABELS | CS_DRAWXLABELS);
pLineChart->AddPoint(100, 100);
pLineChart->AddPoint(200, 200);
pLineChart->AddPoint(300, 300);
PegChartPoint *pPoint = pLineChart->AddPoint(400, 400);
pLineChart->AddPoint(500, 500);
pLineChart->AddPoint(600, 600);
pLineChart->AddPoint(700, 800);
pLineChart->InsertPoint(pPoint, 450, 0);
