Vous êtes sur la page 1sur 45

FoxCharts

Jim Nelson
The Kong Company
21 Los Vientos Drive
Newbury Park C! "1#2$
Voi%e& '($)* +"(,"1")
-a.& '($)* +"(,"1")
/mail& Jim0Nelson123ail4Com
-o.Charts %reates great,looking mo5ern %harts in pure V-P %o5e using N6
!%tive7 %omponents4 8t %an %reate pie an5 5oughnut %harts as well as a
number o9 5i99erent hori:ontal an5 verti%al %harts4 8t takes 9ull a5vantage o9
%olors using soli5 or gra5ient %olors hat%h brushes transparen%ies #D
e99e%ts an5 animation4 There are %ustomi:able tooltips an5 9ull mouse
behavior %ustomi:ation4 The Visual Chart Designer provi5es a me%hanism
whereby a %hart %an be mo5i9ie5 as it is visible on the s%reen by either the
5eveloper or the en5 user4
Table of Contents
1. Overvew
2. Instaaton
3. Settng up Your Data
4. Gettng Started: Smpe Chart Exampes
4.1. Pe, Doughnut, and Smpe Bar Charts
4.1.1. Data-Reated Propertes
4.1.2. Creatng a Smpe Pe Chart
4.2. Ponts, Lnes, and Bar Charts
4.2.1. Data-reated Propertes
4.2.2. Creatng a Smpe Lne Chart
5. Refnng Your Chart
5.1. The Dfferent Chart Types
5.1.1. Pes, Doughnuts, and Smpe Bars
5.1.2. Lnes and Ponts
5.1.3. Bars
5.1.4. Areas
5.2. Depth: Addng the Thrd Dmenson
5.3. Coors
5.3.1. RGB Coors
5.3.2. Transparences
5.3.3. Coors for Shapes
5.3.3.1. Coor Type Seecton
5.3.3.2. Gradent Coors
5.3.3.3. Brush Types
5.3.4. Background Coors
5.4. Legends
5.5. Scang
5.6. Lnes, Bars, Axes, and Tck Marks
5.6.1. Lnes
5.6.2. Bars
5.6.3. Axes
5.6.4. Tck Marks
5.7. TooTps
5.8. Margns
5.9. Chart-Specfc Propertes
5.9.1. Pes, Doughnuts, and Smpe Bars
5.9.2. Lnes and Ponts
5.9.3. Bars
5.9.4. Areas
6. Prntng Your Chart
6.1. Prntng Drecty, Usng GDIPusX Functons
6.2. Savng the Chart to a Fe
6.3. Embeddng n a Report (FRX)
6.4. Prntng wth the Desgner Usng a Vectora Chart n EMF
7. Usng the Vsua Chart Desgner
8. Customzaton
8.1. Obtanng Current Chart Propertes
8.2. Changng Scang Vaues and Legends
8.3. Drawng Custom Images
8.4. Cck and DbCck
8.5. Mouse Movement over a Chart Shape
8.6. Shape Legends
9. Summary
10. Bography
Section 1: Overview
FoxCharts creates great-ookng, modern charts n pure VFP code, usng NO
ActveX components. It can create pe and doughnut charts as we as a
number of dfferent horzonta and vertca charts. It takes fu advantage of
coors, usng sod or gradent coors, hatch brushes, transparences, 3D
effects, and anmaton. There are customzabe tootps and fu mouse
behavor customzaton. The Vsua Chart Desgner provdes a mechansm
whereby a chart can be modfed as t s vsbe on the screen, by ether the
deveoper or the end user.
It s easy to set up and easy to customze. The code s Open Source,
beneftng from a the GDIPusX drawng capabtes, aowng deveopers to
modfy the charts as they see ft. (GDIPusX s a set of Vsua FoxPro 9.0
cass brares that wrap the 603 GDI+ Fat API functons of GDIPus.d.) It s
easy to save to dsk or prnt, and charts can be saved as EMF (Enhanced
MetaFe) mages, resutng n perfect charts when prnted, used n a report,
or exported to a PDF.
Doughnut Sample, with color gradients, detached slices, and shape
transparencies.
The overa structure of FoxCharts s amazngy smpe.
FoxCharts s a contaner whch can be dropped onto any form or cass,
anywhere that a contaner can go. There can be as many nstances of
FoxCharts n a form or cass as desred.
The data to be charted comes from the feds n a cursor (or tabe, or
equvaent). The feds are referenced by ther names.
FoxCharts s property-drven; there s a very arge number of propertes n
the FoxCharts contaner whch ndcate what data s charted, whch type of
chart s used, as we as a the varous egends, coors, scang, etc.
Understandng these propertes and ther reatonshps to one another s the
key to understandng FoxCharts.
After a the propertes are set, cang a snge method creates the chart.
Sample of an Area Chart, with shape transparencies and depth (3-D)
Section 2: Installation
FoxCharts s part of VFPx, a Vsua FoxPro Communty effort to create open
source add-ons for Vsua FoxPro. It s based on GDIPusX, whch s aso part
of VFPx.
To obtan the current verson of FoxCharts, vst the VFPx home page at:
http://www.Codepex.Com/VFPx
From there, navgate to the page for FoxCharts, and downoad three zp
fes:
The most recent reease of FoxCharts. Unzppng t creates a new
foder whch has two sub-foders:
o The Source foder, whch contans a the fes needed to run
FoxCharts. The ony fe whch you drecty reference s
FoxCharts.VCX, whch contans the FoxCharts cass. The
remander of the fes are referenced by FoxCharts; they need to
be somewhere n your path.
o The Sampes foder, whch contans a arge number of sampe
charts. Use DemoStart.PRG to try a the dfferent sampes.
The Hep fe. Unzppng t creates a CHM fe n the same foder. Ths
Hep fe s very thorough; t s qute hepfu to become famar wth t.
|RN_FoxCharts_Toos.Zp. Unzppng t creates a new foder,
|RN_FoxCharts_Toos. Ths foder contans a coupe of add-on toos not
part of FoxCharts proper:
o GetChartDataFromRows.PRG, expaned n Secton 3.
o VsuaChartDesgner.VCX, expaned n Secton 7.
o A "Documentaton foder.
o A Sampes foder, whch contans
VsuaChartDesgner_Sampe.SCX
o An addtona form and cass; you w not reference ether of
these, but both are used by the VsuaChartdesgner.
Section 3: Setting up Your Data
The data whch appears n the chart comes from the feds n a cursor (or
tabe, or equvaent). The aas of the cursor s stored n the requred
property SourceAas:
.SourceAas = Hstory
The data n ths cursor s not accessed drecty; nstead, a new cursor s
created usng an SOL Seect statement. Ths means any orderng or fterng
on the orgna cursor s gnored.
Each data seres n the chart s contaned n a snge fed. The order of the
feds s not reevant, ony ther names. They may appear n any order, and
there can be any number of addtona (not-referenced) feds.
In the exampe cursor beow, ony the coumns YR2005 . YR2009 contan
data that w be charted; f drawn n a ne chart, you woud see fve nes.
Note that there are nu vaues n these feds as we; these w not appear
n the chart.
Dependng on what type of chart s beng drawn, addtona (optona)
coumns may aso be ncuded n the cursor. These coumns are expaned n
deta n Secton 4.
Sample cursor each data series in a separate field
Your source data may not aways be so cooperatve as to be orented so that
each data seres s n a fed; you may have data where each data seres s
actuay a row n a cursor (such as mght be dspayed n a grd).
The cursor beow (SaesHstory2) contans the same data as the cursor on
the prevous page (SaesHstory), but wth each data seres n a separate
row. (In fact, the cursor beow s the orgna source for these exampes; the
cursor on the prevous page was derved from t usng the method descrbed
beow.)

Sample cursor each data series in a separate row
GetChartDataFromRows.PRG transforms a cursor that has ts data seres n
separate rows nto a cursor FoxCharts can use.
GetChartDataFromRows.PRG requres a secondary cursor as we to descrbe
whch feds n the source cursor contan data (or other reevant
nformaton). It s fuy commented.
The foowng converts the cursor above (SaesHstory2) usng the cursor
beow (FedInfo) as the secondary cursor, so that t can be used to create a
chart.
GetChartDataFromRows (Thsform.FoxCharts1, "SaesHstory2", "SdeLegend", "FedInfo",
"SrcFdName", "Legend")
Section 4: Getting Starte: Si!ple C"art #$a!ples
Creatng a rudmentary chart from a cursor (such as from the sampe cursor,
shown earer) s a rather smpe task. A sma number of propertes need to
be set before cang a snge method to create the chart.
There are two dfferent types of charts: those that use a snge data seres
(pes, charts, and smpe bars) and those that can use one or more data
seres (a the rest). The propertes for these two dfferent types of charts
are qute smar, but are not dentca, so they w be descrbed separatey.
Each of the sampes here uses a form BankSampe.VCX from the Sampes
foder. The form contans a snge FoxCharts ob|ect, wth a of ts propertes
defaut. The code sampes provded can be pasted nto the forms custom
method CreateChart after whch the form can be run to create the
sampes.
Section 4.1: Pie, Doughnut and Simple Bar Charts
Section 4%1%1: Data&'elate (roperties
There are ony a few propertes necessary for the smpest of pe charts, as
foows:
SourceAas = The name of the cursor (tabe) contanng the data
ChartType = Type of chart:
o 1 for Pes
o 2 for Doughnuts
o 7 for Snge Bars
o 12 for Horzonta Snge Bars
ChartsCount = 1 (aways ony one data seres)
Feds(1).FedVaue = Name of fed contanng data
There are aso a few optona propertes for pe charts. Each of these
propertes, f used, s the name of a fed n the cursor:
FedLegend - name of the data tem; appears n Sde Legend (see
sampe)
FedCoor - backcoor (ony appes f .CoorType = 1 (Custom) or 3
(Gradent))
FedDetachSce - ndcates f sce s detached (pes and doughnuts
ony)
FedHdeSce - ndcates f sce s hdden (pes and doughnuts ony)
Section 4%1%2: Sa!ple Coe for Creating a Si!ple (ie C"art
Wth Thsform.FoxCharts1 As FoxCharts Of "FoxCharts.vcx"
* Set a the propertes for the chart
* Name of the aas that contans the needed feds that w create the chart
.SourceAas = 'SaesHstory'
* Numerc, the number of data seres.
.ChartsCount = 1
* Numerc, the type or chart to create.
.ChartType = 1 && pe chart
* The name of the fed for the data seres
Wth .Feds(1)
.FedVaue = 'YR2008'
Endwth
* Name of the fed that contans the man egends of the Pe or Doughnut charts
.FedLegend = 'MonthName'
* Name of the fed that contans the custom coors for the chart
.FedCoor = 'BackCoor'
* Name of the fed that ndcates whether the sce w be detached
.FedDetachSce = 'DetachMe'
* The name of the fed that ndcates whether the sce w be hdden
.FedHdeSce = 'HdeMe'
* Create the chart
.DrawChart()
Endwth
Section 4.2: Points, Lines, and Bar Charts
Section 4%2%1: Data&'elate (roperties
There are ony a few propertes necessary for the smpest of ne charts (or
any of the other charts that can have one or more data seres), as foows:
SourceAas = The name of the cursor (tabe) contanng the data
ChartType = Type of chart:
o 4 for Ponts 5 for Lnes
o 6 for Area 10 for Stacked Area
o 8 for Mutpe Bars 13 for Horzonta Mutpe Bars
o 9 for Stacked Bars 14 for Horzonta Stacked Bars
o 11 for Bars n 3D
FedAxs2 = The name of the fed n the cursor contanng the vaues
to be dspayed aong the X-Axs (optona)
ChartsCount = the number of data seres; settng ths creates a
coecton named Feds, whch s referenced beow.
The Feds coecton has one tem for each data seres. The propertes of
each of these tems are as foows:
Feds(N).Fed = Name of fed contanng data for the N-th data seres
Feds(N).Legend = The capton to be used n the sde-egend for the
N-th data seres (optona)
Feds(N).Coor = The RGB vaue to be used for the shape drawn for
the N-th data seres (optona); ths ony appes f CoorType = 1 or 3
Feds(N).Shape = Shape to be used for Pont or Lne Charts.
Section 4%2%2: Sa!ple Coe for Creating a Si!ple )ine C"art
Wth Thsform.FoxCharts1 As FoxCharts Of "FoxCharts.vcx"
* Set a the propertes for the chart
* Name of the aas that contans the needed feds that w create the chart
.SourceAas = 'SaesHstory'
* Numerc, the type or chart to create.
.ChartType = 5 && = Lnes
* Numerc, the number of data seres.
.ChartsCount = 5
* Numerc, the depth n pxes, smuatng a 3D effect (0 = pan)
.Depth = 0
* The name of the fed contanng the vaues to be dspayed aong the X-Axs.
.FedAxs2 = 'MonthName'
* The feds for each of the data seres, and ther assocated egends
WITH .Feds(1)
.FedVaue = 'YR2005'
.Legend = 'Saes 2005'
ENDWITH
WITH .Feds(2)
.FedVaue = 'YR2006'
.Legend = 'Saes 2006'
ENDWITH
WITH .Feds(3)
.FedVaue = 'YR2007'
.Legend = 'Saes 2007'
ENDWITH
WITH .Feds(4)
.FedVaue = 'YR2008'
.Legend = 'Saes 2008'
ENDWITH
WITH .Feds(5)
.FedVaue = 'YR2009'
.Legend = 'Saes 2009'
ENDWITH
Endwth
Section *: 'efining Your C"art
Section 5.1: The Dierent Chart T!pes
There are 16 dfferent chart types. Sampes of each are dspayed beow.
The sampes were a created usng the VsuaChartDesgner_Sampe form n
the Sampes foder.
Note that for each of the groups beow, there are a few propertes that appy
ony to that group. These are speed out n deta n 5.9.
Section *%1%1: (ies an Doug"nuts

ChartTpe ! " #ie ChartTpe $ " Doughnut
Section *%1%2: (oints an )ines

ChartTpe % " #oints ChartTpe & " 'ines
Section *%1%3: +ars

ChartTpe ( " Single )ar ChartTpe !$ " *ori+ontal Single )ar

ChartTpe , " -ultiple )ars ChartTpe !3 " *ori+ontal
-ultiple )ars

ChartTpe . " Stac/ed )ars ChartTpe !% " *ori+ontal
Stac/ed )ars
Section *%1%3: +ars ,Continue-

ChartTpe 3 " 0ull-Stac/ed )ars ChartTpe !& " *ori+ontal 0ull-
Stac/ed )ars
ChartTpe !! " )ars in 3D
Section *%1%4: .rea
ChartTpe 1 " Area ChartTpe !2 " Stac/ed Area
ChartTpe !1 " 0ull-Stac/ed Area
Section 5.2: Depth " adding the third dimension
The uson of a thrd dmenson can be added to charts by usng the Depth
property.
Ths 3-D effect changes fat, unnterestng charts nto charts that appear to
snk nto the screen. See, for exampe, the foowng chart:
Sample using Depth " !2
The Depth property s the number of pxes used n creatng the depth
uson. It s nteger-vaued; ts nomna range s between 0 and 50.
It s frequenty used n con|uncton wth the AphaChanne property, whch
contros the eve of the transparency of the shape ob|ects on the chart. See
5.3.2.
Whe the Depth property s of great vaue n most charts, t can make both
Pont and Lne Charts very dffcut to read. These work better wth no depth
(Depth = 0).
Section 5.#: Colors
Section *%3%1: 'G+ Colors
A of the ob|ects seen n a chart have famar RGB coors assgned to them.
For those that are text-orented (caed Legends - see Secton 5.4), there are
coors for both the foreground (text) and the background.
The coor propertes are:
AxsCoor - the coor used for the horzonta axes
BackCoor - the prmary background coor for the entre chart
BackCoor2 - the secondary background coor for the entre chart;
used to create coor gradents for the chart background (more on ths
n a bt)
ScaeBackCoor - the coor for the bars (ether horzonta or vertca)
that appear on a but pe and doughnut charts
ScaeLneCoor - the coor for the nes (ether horzonta or vertca)
that appear on a but pe and doughnut charts
ScaeLneZeroCoor - the coor for the ne Y = 0 (that s, aong the X-
Axs); appes ony f the chart shows both postve and negatve vaues
and the property ShowLneZero s .T.
SeectedShapeCoor - the coor used when the mouse ponter s
moved over one of the chart shapes; appes ony f the property
ShowCoorOnMouse s .T.
ForeCoor and Backcoor - for each of the Legends - see Secton 5.4
Much more can be done wth coors, however, to make them more
appeang: transparences, gradent coors, and brush types.
The foowng chart w be used as an exampe throughout ths secton. It s
a smpe doughnut chart, created wth a depth of 30 but no transparences.
Section *%3%2: Transparencies
Transparen%y s the term used to descrbe how much an ob|ect obscures
whatever has been drawn behnd t.
Transparency vaues, aso caed AphaChanne, range from 0 (competey
transparent) to 255 (competey opaque). Ths s smar n concept to the
VFP BackStye property, whch has vaues of ether 0 (transparent) or 1
(opaque).
A number of dfferent FoxCharts coors have an assocated transparency
vaue:
AphaChanne - transparency for the shape ob|ects on the chart; ths s
the transparency whch has the most vvd effect; see beow
AxsApha - transparency for the X and Y axes
BackCoorApha - transparency for the background coors for the chart
ScaeBackApha - transparency for nes and bars drawn for charts
(other than pe and doughnut charts)
ForeCoorApha - for Legends, for the foreground coor.
BackCoorApha - for Legends, for the background coor; usuay eft at
0
Beow s the same chart as the prevous page, but wth a vaue for
AphaChanne of 230.
Section *%3%3: Colors for S"apes
Section &.3.3.!3 Color Tpe Selection
There s a surprsngy arge number of ways to assgn the coors used for
the shapes that appear n a chart. These are specfed by the property
CoorType. Its possbe vaues are:
0 = Basc coors
1 = Custom (the defaut); coors are used based on the assgnments to
the varous propertes descrbed n Secton 4.
2 = Random
3 = Gradent; the frst coor used s Feds(1).coor, and a gradent s
apped endng wth amost whte.
4 thru 27: Pre-assgned coor paettes
The chart on the prevous page was drawn usng CoorType = 14. Here s
the same chart wth CoorType = 21
Section &.3.3.$3 4radient Colors
CoorType = 3, as noted above, produces gradent coors - that s, coors
whch transton from one coor to another. In ths case, they transton from
the man coor (red) to amost whte.
Section &.3.3.33 )rush Tpes
Brush Types descrbe how the coors are brushed onto the shape ob|ects.
The property BrushType can take one of these vaues:
1 = Sod coors (what has been shown thus far)
2 = Gradent coors
3 = Monochrome
If gradent coors are used, the foowng propertes appy:
GradentLeve - descrbes destnaton coor; 10 = whte, -10 = bank
GradentInvertCoors - f .T. the man and destnaton coors are
nverted
GradentPoston - ndcates where the hghest ntensty occurs
GradentDrecton - drecton of gradency; top to bottom, eft to rght,
etc.
GradentType - sgma be or tranguar
The chart beow was drawn usng a gradent brush (eavng a the
secondary propertes wth ther defaut vaues).
Section *%3%4: +ac/groun Colors
There are aso coors that can be apped to the background of the chart to
soften (and hghght) ts appearance:
BackCoor - the prmary background coor for the entre chart
BackCoor2 - the secondary background coor for the entre chart;
used to create coor gradents for the chart background (more on ths
n a bt); optona
BackGradentMode - f two background coors are used, the drecton
of the gradent between them; top to bottom, eft to rght, top eft to
ower rght, or top rght to ower eft
BackCoorApha - transparency for the background coors for the chart
If ony one background coor s used, that coor s apped to the entre
background.
If two background coors are used, then the background transtons from one
of the coors to the other, based on drecton ndcated by
BackGradentMode.
The chart beow was created wth two background coors, a ght bue and a
ght yeow, wth a drecton from top eft to bottom rght, and a
transparency of 200.
Section 5.4: Legends
There are eght dstnct Legen5s that can be dspayed on a FoxCharts chart.
(See the exampe beow.) They are ndvduay confgurabe.
Each egend s an ob|ect (a abe) n the FoxCharts contaner. However, they
do not functon ke norma VFP abes. They ony exst so propertes can be
set for them (expaned n deta beow); FoxCharts uses these propertes
when t creates the chart. Thus, method code and settngs for any other
propertes are gnored.
There are a number of propertes that appy to a egends that behave
exacty as they woud for norma propertes; they w not be expaned n
deta here.
Agnment FontSze
BackCoor FontBod
Capton FontItac
ForeCoor FontStrkeThru
Format FontUnderne
FontName FontCharSet
In addton, there are four custom propertes:
ForeCoorApha - ForeCoor Transparency; see Secton 5.3.2
BackCoorApha - BackCoor Transparency; see Secton 5.3.2.
Normay zero
Rotaton - Rotaton ange (0-360) for the egend. Measured n
degrees, postve for cockwse, negatve countercockwse. Used n
con|uncton wth the Agnment property; norma usage s a sma
postve vaue wth Agnment =0 (drops down to the rght) or a sma
negatve vaue wth Agnment =1 (comes up from the ower eft).
Most frequenty used wth the egends aong the XAxs (XAxs2Legend)
when there s not enough room for a egends f dspayed
horzontay.
RotatonCenter - Rotaton around the center of the egend
Addtona specfcs for each egend:
SdeLegend -The text dspayed s set dfferenty for pe/donuts
(property FedLegend; see Secton 4.1.1) and the rest of the chart
types (property .Feds(N).Legend; see Secton 4.1.2). There are three
reated propertes:
o ShowSdeLegend - Logca; f .F., SdeLegends are not dspayed
o LegendPoston - Contros where the SdeLegend s dspayed;
possbtes are on eft or rght, top or bottom, horzonta or
vertca
o LegendHdeWhenNu - Logca; for pes, doughnuts, and smpe
bars, ndcates whether the egend s not dspayed f the vaue
s .Nu.
Shapeegend - The word shape here appes to a the varous shapes
that can be dspayed: sces, ponts, bars, etc. There are three reated
propertes:
o ShowVauesonShapes - Logca; f .F., ShapeLegends are not
dspayed
o PeShowPercent - Logca; f .T., percents are dspayed nstead
of vaues
o ShapeLegendExpresson - If non-empty, a character expresson
to be executed; returns the new ShapeLegend text. See Secton
8.6
XAxs - Does not appy to pes and doughnuts
XAxs2Legend - The text dspayed s obtaned from the source cursor,
n the fed dentfed by .FedAxs2. If there are too many egends to
dspay, they can ether be rotated (see above) or some of them can
be eft bank; e.g., ony fng n every other or every thrd egend.
Does not appy to pes and doughnuts
YAxs - Does not appy to pes and doughnuts
Scaeegend - The text dspayed s obtaned from scang, whch s
expaned n deta n the next secton. Does not appy to pes and
doughnuts. There s one reated property:
o ShowScae - Logca; f .F., ScaeLegends are not dspayed
For each of the egends, the chart w expand to f the unused space f the
egend s bank or does not appy.
Section 5.5: Scaling
;%aling refers to the determnaton of whch vaues are dspayed on the
vertca axs (Y-Axs). Ths ncudes the mnmum and maxmum vaues
dspayed, as we as the number of egends dspayed and the nterva
between the egends. The defaut s that a of these vaues are cacuated
automatcay. The propertes beow are used to overrde ths defaut
cacuaton.
ShowScaes - f .F., scaes are not dspayed
ScaeDvder - A dspayed vaues n the ScaeLegend are dvded by
ths vaue. Normay the vaue s one; other vaues (presumaby
powers of ten) aow for easer dspay of arge vaues ("A vaues n
$Mons")
ShowVaueZero - Forces dspay of the X-Axs (ne Y=0). Normay .T.,
a settng of .F. aows dspay of a chart that does not ncude a ne for
zero
Scae - Step sze between horzonta bars (see secton 5.6.3). If zero,
ths vaue s cacuated automatcay, and s chosen so that the
ncrement between successve scae vaues w be a power of ten
tmes one of 1, 2, 2.5, or 5.
BarsperScae - Number of horzonta bars (see Secton 5.6.3) per each
egend.
MnNumberScaeLegends - Mnmum number of scae egends to
dspay (f Scae s cacuated automatcay)
MnVaue - Mnmum vaue to be dspayed; f .F., ths w be cacuated
automatcay. The mnmum egend dspayed w be a mutpe of the
Scae property that s ess than or equa to ths vaue.
MaxVaue - Maxmum vaue to be dspayed; f .F., ths w be
cacuated automatcay. The maxmum egend dspayed w be a
mutpe of the Scae property that s greater than or equa to ths
vaue.
Scaling e5ample
Notes:
The sampe above was created usng MnVaue of 250,000, MaxVaue of
750,000 and of MnNumberScaeLegends of 4.
Nothng prevents settng vaues for MnVaue or MnVaue that do not
ncude a the vaues beng dspayed; a ne chart, n partcuar, can show
vaues that go competey off the norma chart area, even off the vsbe
page, as n the exampe above.
The formattng of the egends on the vertca axs s descrbed n Secton 5.4
Section 5.$: Lines, Bars, %&es, and Tic' (ar's
Ths secton refers to the nes, bars, axes, and tck marks whch can be
drawn wthn a charts (except for pes and donuts).
ShowAxs - f .F., no nes, bars, or axes are dspayed
Section *%0%1: )ines
ScaeBackLnesType - Numerc, ndcatng whch nes (f any) are
drawn: horzonta (defaut), vertca, nether, or both
ScaeLneCoor - Numerc, RGB vaue for the coor
AxsApha - Numerc, transparency (ths vaue s used for both nes
and axes)
ScaeBackLnesWdth - Wdth, n pxes
ScaeBackLnesDash - Lne stye, n pxes (sod, dotted, etc)
There are separate settngs for ne Y=0 (dspayed when the chart
shows both postve and negatve vaues)
ShowLneZero: To force separate coor for the X-Axs
ScaeLneZeroCoor: Numerc, RGB vaue for the coor for the X-Axs
)oth *ori+ontal and 6ertical lines, dotted lines (Scale)ac/'inesDash " !)
Section *%0%2: +ars
<ars here means the aternatng background shaded areas n a chart
ScaeBackBarsType - Numerc, ndcatng whch bars (f any) are to
drawn: horzonta (defaut), vertca, nether, or both
ScaeBackCoor - Numerc, RGB vaue for the coor
ScaeBackApha - Numerc, transparency (ths vaue s used for both
nes and bars)
)oth *ori+ontal 7ars, color " ($&&, $&&, 2), Scale)ac/Alpha " $22
Section *%0%3: .$es
AxsCoor - Numerc, RGB vaue for the coor
AxsApha - Numerc, transparency (ths vaue s used for both nes
and axes)
Section *%0%4: Tic/ 1ar/s
ShowAxs2Tcs - f .F., Tck Marks are not dspayed
TcLength - Length, n pxes
-in6alue of -$22,222, Scale'ine8eroColor of ($&&,2,2), Tic'ength of
!$
Section 5.): ToolTips
Tootps n FoxCharts emuate natve VFPs tootps, n that they dspay a
pop-up contro as the mouse passes over a shape n the chart.
The tootps n FoxCharts are mpemented competey dfferenty however;
there s a TooTp contro (a abe) n the FoxCharts contaner, and you can
modfy the norma propertes that appy to a abe, ncudng the font name
and sze, background coor, etc.
At runtme, FoxCharts creates a form eve abe for ts tootps and transfers
a the approprate propertes to t. Thus, care must be used n determnng
what propertes can be modfed; see the Hep fe for more detas.
Ths requres that ThsForm.ShowTps = .T.
Method ShapeTooTp aows further customzaton; see the Hep fe
for detas.
You can aso use your own TooTps cass, or even the VFPX Ct32
BaoonTps cass. If so, you have to manage the tootps by yoursef.
Start by dsabng the current tootps settng ShowTps to .F., and put
your custom code n ShapeMouseEnter and ShapeMouseLeave events.
For exampes of ths, see the Hep fe
Section 5.*: (argins
Fve propertes contro the empty space around the permeter of a chart. A
of these propertes are expressed n pxes.
Margn - the number of pxes eft bank around the entre chart
MargnTop - addtona margn to be added to the top of the chart
MargnLeft - addtona margn to be added to the eft of the chart
MargnRght - addtona margn to be added to the rght of the chart;
more key to be used than the others, as the Sde Legends can butt
up aganst the rght margn of the chart
MargnBottom - addtona margn to be added to the bottom of the
chart
Section 5.+: Chart,Speciic Properties
Section *%2%1: (ies an Doug"nuts
PeCompensateAnges - f .T., a wde epse; ese, see PeForceCrce
PeForceCrce - f .T., a crce; ese a norma epse
PeLegendDstance - The reatve dstance of the shape egend n the
sce to the radus of the crce; 0 = center of the pe; 1 = edge of the
pe
PeShowPercent - Logca, ndcates whether the vaues dspayed n
the shapes are percents. Ony appes f ShapeLegends s .T.
PeDetachSceonCck - Logca, aows detachment of a sce on a
mouse cck
PeDetachSceonLegendCck - Logca, aows detachment of a sce
on mouse cck over the assocated sde egend
PeDetachPxes- The number of pxes that a sce s detached
PeDetachAnmatonSteps - The number of steps taken when a sce s
detached, producng an anmaton effect
PeGradCenterDstance - The reatve dstance of the center of center
pont when the gradent brush s apped; 0 = center of the pe; 1 =
edge of the pe. Used together wth .PeGradCenterAnge
PeGradCenterAnge - The ange of the center of center pont when the
gradent brush s apped; 0 to 360; 0 = rght; 90 = down, 180 = eft,
270 = up. Used together wth .PeGradCenterDstance
PeEnhancedDrawng - Enabes enhanced drawng mode, wth a
edges drawn separatey, provdng a better vsua effect.
PeDrecton - Indcates the drecton that sces are drawn; 0 =
cockwse, 1 = countercockwse.
Section *%2%2: )ines an (oints
The foowng propertes ony appy f .Depth = 0.
LneCaps - Logca, ndcates whether ne caps are shown. LineCaps
are the shapes that are dspayed at each data pont.
PontShapeWdth - The wdth of the ne caps, n pxes
PontCapsShape - Shape used for each ne
o 0 = Dfferent shapes for each ne
o 1 to 10 = Same shape for each ne (crces, squares, etc.)
Section *%2%3: +ars
ShowPercentages - Logca, ndcates whether the vaues dspayed n
the shapes are percents. Ony appes f ShapeLegends s .T.
BarsSpacesBetween - the number of pxes between bars
BarType - The type of bar used:
o 0 = Rectanguar
o 1 = Cynder
o 2 = Trange
BarsLegendType - Legend poston:
o 0 = Defaut
o 1 = Vertca, top to bottom
BarsLegendDrecton - Legend drecton:
o 0 = Horzonta
o 1 = Vertca, top to bottom
o 2 = Vertca, bottom to top
Section *%2%4: .rea
Area3DTop - Logca, ndcates whether a ne w be drawn on the top
of the 3D Area chart.
AreaDrawBorders - Logca, draws borders around each Area pece.
Section 0: (rinting Your C"art
Four dfferent mechansms are provded to aow you to use your chart (by
savng or prntng) after t s created.
Section $.1: Printing Directl!, -sing .D/Plus0 1unctions
LOCAL oBmp as xfcBtmap
oBmp = Thsform.Foxcharts1.oBmp
oBmp.ToPrnter(tnStretch, tcPrnterName, tnOrentaton, tnAgnment)
The parameters are descrbed n deta n the Hep fe.
Section $.2: Sa2ing the Chart to a 1ile
Thsform.Foxcharts1.SaveToFe (tcFeName)
There are a number of mage formats avaabe. The format s determned
by the extenson of the fe name. The recommended formats are PNG and
EMF. Other supported formats ncude |PEG, GIF, and TIFF.
Section $.#: 3m4edding in a 5eport 61507
A chart created by FoxCharts can be used drecty n a report by addng an
mage to the report and settng ts propertes appropratey.
Drop an "Pcture/OLEBoundContro" on the report desgner surface. In the
Propertes daog that appears, seect "Expresson or varabe name" for the
Contro Source Type. In the "Contro source" TextBox, put the mage ob|ect
name: oFoxChart.
The report desgner needs to access the mage ob|ect, so the ob|ect must be
a Prvate or Pubc varabe. Immedatey before cang the report, use code
smar to ths:
SET REPORTBEHAVIOR 90
PRIVATE oFoxChart
oFoxChart = ThsForm.Foxcharts1.ChartCanvas
REPORT FORM ...
Section $.4: Printing 8ith the Designer using 9ectorial Chart in 3(1
Ths opton s very smar to the prevous opton, except the mage s stored
n an EMF mage fe, whch aows perfect chart mages n reports, as EMF
mages are redrawn each tme to the desred sze. Instead of storng an
mage, an EMF mage fe stores a st of functon cas ssued to the Wndows
graphcs ayer GDI n order to dspay an mage on screen.
The procedure for usng an EMF fe s dentca to that n secton 6.3, except
use oFoxChart.DrawReport() as the contro source.
The report desgner needs to access the mage ob|ect, so the ob|ect must be
a Prvate or Pubc varabe. Immedatey before cang the report, use code
smar to ths:
SET REPORTBEHAVIOR 90
PRIVATE oFoxChart
oFoxChart = ThsForm.Foxcharts1
REPORT FORM ...
For more on EMF mages, see http://en.wkpeda.org/wk/Enhanced_Metafe
Section 3: 4sing t"e 5isual C"art Designer
The process of creatng a great-ookng, modern chart s an teratve
process. There are a seemngy nfnte number of combnatons of chart
types, coors and coor paettes, transparences, gradents and brush types,
scang and other propertes to be consdered. There are approxmatey one
hundred dfferent propertes that can be set. Some propertes work ony n
combnaton. Others appy ony under certan crcumstances. Achevng an
attractve fna resut may take dozens (hundreds?) of teratons.
Beyond ths, there are matters of persona taste. In partcuar, choces of
desrabe coors can vary wdey from ndvdua to ndvdua.
Thus, t s extremey ronc that to produce a chart, the most vsua of
resuts, a the avaabe toos have been competey non-vsua - whether
settng propertes n code (as has been done throughout ths paper), or by
usng PEM Edtor or ts outdated predecessor, the Property Wndow.
The Vsua Chart Desgner (herenafter referred to as VCD) was born to f
ths vacuum. It s desgned to:
run when a chart has aready been drawn and s vsbe on the screen
aow you to change the propertes of the chart and see the effect of
the change mmedatey. Amost a propertes can be changed; those
few excuded are prmary the data-reated propertes dscussed n
Secton 3
vew a st of a propertes (and ther vaues), or a propertes that are
non-defaut, or a propertes that have changed snce a gven cut-off
pont
copy the st of propertes to the cpboard (optonay wth ther
descrptons) n a format that aows them to be pasted drecty nto
the method that creates the chart. Not surprsngy, ths s the method
used to create a of the sampes provded n ths paper.
The effects of ths are two-fod:
The deveoper can concentrate hs/her tme on creatng the data
(Secton 4) and makng a reasonabe start on the remander of the
propertes. Then, he can run the chart, use VCD to modfy the settngs
as needed, export the st of changed propertes to the cpboard, and
paste them back nto the form to re-create the chart exacty as
desred.
Ths can aso be provded for capabe end users. Ths capabty aows
them to fne-tune reports to ther own needs and tastes. In a
suffcenty robust system, one coud save these settngs for easy
retreva, by user.
The exampe beow shows VCD n acton. The exampe s the
VsuaChartDesgner_Sampe form n the Sampes foder. The Vsua Chart
Desgner form tsef (on the bottom) s opened by cckng on the Chart
Optons button.
Changng any of the propertes n VCD, on any of the nne tabs n the
pageframe, causes the chart to be re-drawn mmedatey. In addton, there
are tootps on each ob|ect whch st the name of the property that s
controed, ts vaue, and ts descrpton (as you woud see n PEM Edtor or
the Property Wndow)
The Propertes tab can be vsted at any tme to see a st of the FoxCharts
propertes. The st can optonay ncude the descrpton for each property
and/or the approprate Wth / EndWth structure. The st can then be saved
to the cpboard for ater pastng.
The dstncton between non-defaut propertes and changed propertes
may not be mmedatey cear, but s qute mportant.
Non-Defaut Propertes s the standard defnton of a propertes that have
been changed, ever.
Changed Propertes means a propertes that have been changed snce the
ast tme a cut-off was set. Cut-offs are set by usng the method
SaveChartPropertes(). (See secton 8.1). They are aso set by usng the
Cear Changed Propertes button above.
A typca use of Changed Propertes s to ncude t mmedatey after the
ca to DrawChart() n the form creatng the chart. Thus, ony the propertes
changed thereafter n VCD woud appear n the st of Changed Propertes.
VCD can be added to any exstng chart by addng a snge contro to the
FoxCharts contaner: cmdChartOptons of VISUALCHARTDESIGNER.VCX
Ths contro aso has a property, DeveopmentOny, whch w make t
nvsbe and dsabed when not n deveopment mode.
Section 6: Custo!i7ation
There are a number of dfferent opportuntes for customzaton avaabe.
Each of the methods s descrbed n deta n the Hep fe and/or n ther
comments. There are aso exampes of some of these n the Sampes foder.
Section *.1: :4taining Current Chart Properties
SaveChartPropertes - sets a cut-off pont so that a ater ca to
GetChartPropertes (beow) wth a parameter for Changed Propertes
w return ony those propertes that have changed n the nterm.
GetChartPropertes - returns a st of chart propertes; ths method s
what s caed on the Propertes tab of the Vsua Chart Desgner. A
of the contros on that tab are used to create the parameters passed
to ths method.
Section *.2: Changing Scaling 9alues and Legends
GetScaeVaue - returns the st of vaues dspayed as the scae
egends. The defaut method returns vaues n dentca steps. The
comments ndcate how to create scae egends where the steps are
not a the step sze. (See form |N_Sampe3 n the Sampes foder.)
GetScaeLegend - Pared wth GetScaeVaue to return the scae
egends; can aso be used to over-rde ndvdua scae egends wth
seected text; Zero for the number 0, for nstance.
Section *.#: Dra8ing Custom /mages
AfterChart: An event that occurs mmedatey after the chart s drawn,
but st before the mage ob|ect s updated. Use ths when you want to
draw somethng specfc n your chart not reated to the chart
propertes, such as a watermark or your company's ogo. Ths
functonaty s for users that are famar wth GdPusX. In order to
draw n the Chart canvas, you w need to use the GdPusX drawng
commands, such as "DrawImage". GdPusX support s not n the scope
of ths whte paper (nor the Hep fe, for that matter). Pease refer to
GdPusX at the VFPX web ste for more detaed nformaton, or post
your questons n the VFPX forums at Codepex.
Section *.4: Clic' and D4lClic'
When these events occur, a number of propertes are pre-popuated nto the
FoxCharts contaner; fu detas and exampes can be found n the Hep fe.
Section *.5: (ouse mo2ement o2er a Chart Shape
ShapeMouseEnter - occurs when the mouse enters an ob|ect
ShapeMouseLeave - occurs when the mouse eaves an ob|ect
ShapeMouseMove - occurs when the mouse moves over an ob|ect
ShapeShapeTooTp - occurs before the defaut tootp of FoxCharts s
dspayed
When any of these events occur, a number of propertes are pre-popuated
nto the FoxCharts contaner; fu detas and exampes can be found n the
Hep fe.
Section *.$: Shape Legends
Property ShapeLegendExpresson, f not empty, specfes an expresson
whch w be executed to repace the defaut ShapeLegend text. Ths aows
fu customzaton of the text to be dspayed n (or near) chart shapes. It
may be any vad VFP expresson.
A fu descrpton of ShapeLegendExpresson can be found n the Hep fe.

Contact Infor!ation
Ths document was wrtten by |m Neson.
|m.R.Neson@GMa.Com
(805) 498-9195 (Voce)
(720) 837-3536 (Ce)

Vous aimerez peut-être aussi