Use ChartFX.VBX
Question
I am trying to use the CHARTFX VBX component in an application. I am still relatively low on the learning curve for Delphi and I've had no experience with Visual Basic. Besides the Object Inspector, how can I find out what
methods, etc. are available for manipulating this component?
Answer
A:
Although its usefulness can be debated, there is context-specific help
available for ChartFX. Drop the component onto a form, then press F1 while
it is selected.
ChartFX
Question
I have tried to introduce two spin
edit boxes to stand for the NSeries and NValues properties. When I
run the program, I try setting these properties to the value of the
spinedit.
I get the 'Error setting property at index #13 (and #14). I assume this is
because I have not closed down the data before trying to alter the values.
I have read the instructions that came with it and am still non the wiser about
how to open and close channels.
Answer
A:
This is the code I use for setting up the chartfx.
chart1.Opendata[cod_values]:=makelong(no_of_series,no_of_classes);
{adjust series values}
chart1.closedata[cod_values]:=0;
A:
unit TstChart;
interface
uses=20
WinTypes, WinProcs, Classes, Graphics, Forms, Controls, Menus,
Dialogs, StdCtrls, Buttons, ExtCtrls, Tabs,
ChartFX, {It seems to be necessary to include this for certain constants
such as COD_VALUES}
VBXCtrl, Chart2fx;
type
TF_Chart =3D class(TForm)
SpeedPanel: TPanel;
ExitBtn: TSpeedButton;
NB: TNotebook;
TB: TTabSet;
Chart1: TChartFX;
Chart2: TChartFX;
procedure ExitItemClick(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure TBClick(Sender: TObject);
procedure FormResize(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
Procedure Build1( Ch : TChartFX );
Procedure Build2( Ch : TChartFX );
end;
var
F_Chart: TF_Chart;
implementation
{$R *.DFM}
procedure TF_Chart.ExitItemClick(Sender: TObject);
begin
Close;
end;
procedure TF_Chart.FormCreate(Sender: TObject);
begin
TB.Tabs :=3D NB.Pages;
NB.PageIndex :=3D 0;
Build1( Chart2 );
Build2( Chart2 ); {adds values, legends etc to Chart2}
end;
procedure TF_Chart.TBClick(Sender: TObject);
begin
NB.PageIndex :=3D TB.TabIndex;
end;
Procedure TF_Chart.Build1( Ch : TChartFX );
begin
{This procedure alters the properties that can be set at design
time or run time. The Design method of doing things is shown
in the comments}
with Ch do begin
Adm[ CSA_GAP ] :=3D 25.0;
{Design: Use the AdmDlg propert to change the Y Gap}
pType :=3D BAR or CT_LEGEND;
{Design: Use the ChartType property to change from 1 - line
to 2 - bar.}
DecimalsNum[ CD_YLEG ] :=3D 0;
{Design: Change the Decimals Property from 2 to 0}
Stacked :=3D CHART_STACKED;
{Design: Change the Stacked property from 0 - None to 1 - Normal}
RightGap :=3D 20;
{Design: Same}
OpenData[ COD_COLORS ] :=3D 2;
Color[ 0 ] :=3D clBlack;
Color[ 1 ] :=3D clYellow;
CloseData[ COD_COLORS ] :=3D 0; {Ugh!!}
{Design: To change the colors of the 2 series:
1) Make sure ThisSerie is set to 0. Change
ThisColor to clBlack.
2 Set ThisSerie to 1. Change ThisColor to
clYellow.}
Title[ CHART_TOPTIT ] :=3D 'Articles vs Titles';
Title[ CHART_LEFTTIT ] :=3D 'CCM';
Title[ CHART_BOTTOMTIT ] :=3D 'Cards';
{Design: click on the TitleDlg property and
set Top, Left and Bottom titles}
end;
end;
Procedure TF_Chart.Build2( Ch : TChartFX );
{This procedure sets properties that cannot (as far as I can determine)
be set at design time}
const
XAbbrevs : array[ 0..4 ] of string[ 4 ] =3D
( 'Acc', 'Bar', 'Mas', 'Amex', 'Din' );
SeriesTitles : array[ 0..1 ] of string[ 8 ] =3D
( 'Articles', 'Titles' );
XTitles : array[ 0..4 ] of string[ 20 ] =3D
( 'Access', 'Barclaycard', 'Mastercard', 'American Express',
'Diners' );
{of course you would normally read xtitles and
values from a database}
Values : array[ 0..1, 0..4 ] of double =3D
( ( 50, 60, 70, 80, 90 ),
( 30, 35, 25, 37, 42 ) );
var
i, SerieNo : integer;
begin
with Ch do begin
LegendWidth :=3D 120;
{Set Number of series, number of values ******************}
OpenData[ COD_INIVALUES ] :=3D MAKELONG( 2, 5 );
CloseData[ COD_INIVALUES ] :=3D 0;
{*********************************************************}
OpenData[ COD_VALUES ] :=3D 2;
{if you omit the above statement, (in which you enter the
number of SERIES not VALUES), and the CloseData below,
the assignment to Values does not create an error, but
does not work!
Assigning Values to Legend, KeyLeg works without an
OpenData/CloseData}
ThisSerie :=3D 0;
for i :=3D 0 to 1 do
SerLeg[ i ] :=3D SeriesTitles[ i ];
for i :=3D 0 to 4 do=20
begin
Legend[ i ] :=3D XTitles[ i ];
KeyLeg[ i ] :=3D XAbbrevs[ i ];
end;
SerieNo :=3D 0;
for SerieNo :=3D 0 to 1 do=20
begin
ThisSerie :=3D SerieNo;
for i :=3D 0 to 4 do
Value[ i ] :=3D Values[ SerieNo, i ];
end;
CloseData[ COD_VALUES ] :=3D 0;
end;
end;
procedure TF_Chart.FormResize(Sender: TObject);
var
w, h : longint;
begin
w :=3D NB.Width;
H :=3D NB.Height;
{enlarge/reduce chart size if necessary}
Chart1.Width :=3D W - 18;
Chart1.Height :=3D H - 12;
Chart2.Width :=3D W - 18;
Chart2.Height :=3D H - 12;
{move Exitbutton close to right edge}
ExitBtn.Left :=3D SpeedPanel.Width - 32;
end;
end.