VBX / OCX

VBX / OCX

Use ChartFX.VBX
VBX in a Delphi Application, how to distribute
ChartFX
ChartFX - Min Max
ChartFX example


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.




VBX in a Delphi Application, how to distribute

Question


Do I need vbrun100/200/300.dll to use VBXs?



Answer


A:

To use any VBX controls with Delphi compiled EXE, you need to distribute BIVBX11.DLL (found in \WINDOWS\SYSTEM - a Borland redistributable).




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.


ChartFX - Min Max

Question


I am using the ChartFX VBX that ships with Delphi 1.0. I put low values

into Value[0], all these values (x) are greater than -1 and less that 5.

When the graph is displayed the y-axis displays numbers from 0 to 94.68,

thus my result is a very flat graph.



How can I set this graph that it adjusts the y-axis according to the

highest and lowest values?

Answer


This is how you do it with ChartFX in Delphi 2.... I assume it's the same in

D1...



  cfxStockTrends.Adm[CSA_MIN] := X;         //set minimum of Y axis

  cfxStockTrends.Adm[CSA_MAX] := Y;       //set maximum of Y axis


ChartFX example

Question




Answer


The instructions that came with Delphi help is indeed a bit encrypted,

particularly if you are not a VBX user...



Any way, the following example should set the values etc for ChartFX:



{The code gets data from a database and plots it}



begin

MyTable.active := True;		{open database}

MyTable.first;

MyChart.title[CHART_BOTTOMTIT] := 'X-axis label';

MyChart.title[CHART_LEFTTIT] := 'Y-axis label';

MyChart.OpenData[COD_XVALUES] := MakeLong(numOfSeries,numofPoints);

MyChart.OpenData[COD_VALUES] := MakeLong(numOfSeries, NumofPoints);

MyChart.ThisSerie := SeriesNum;		{start with 0}

While MyTable.EOF <> True do

begin

     MyChart.value[i] := MyTable.FieldByName('SOMEFIELD').AsFloat;

     MyChart.Xvalue[i] := MyTable.FieldByName('SOMEOTHERFIELD').AsFloat;

     MyTable.next;

     i:=i+1;	{you need to define and initialize 'i' of course}

end;

MyChart.CloseData[COD_Values] := 0;

MyChart.CloseData[COD_XValues] := 0;

MyTable.active := False;	{close database}

end;



{Note this code is for an xy scatter chart. If you want to use any other

type of chart in ChartFX, you will not need to set values for COD_XVALUES}




Close    To Top
  • Prev Article-Programming:
  • Next Article-Programming:
  • Now: Tutorial for Web and Software Design > Programming > delphi > Programming Content
    Photoshop Tutorial
     

    Special Effect

      3D Effect
      Photoshop Articles
    Programming Tutorial
     

    C/C++ Tutorial

      Visual Basic
      C# Tutorial
    Database Tutorial
     

    MySQL Tutorial

      MS SQL Tutorial
      Oracle Tutorial
    Geek Tutorial
     

    Blogging Tutorial

      RSS Tutorial
      Podcasting Tutorial
    Graphic Design Tutorial
      Coreldraw Tutorial
      Illustrator Tutorial
      3D Tutorials
    Webmaster Articles
     

    Domain Service

      Web Hosting
      Site Promotion
    Java Tutorial/ Articles
     

    Java Servlets

      JavaEE Tutorial
     

    JavaBeans Tutorial

    XML Tutorial/ Articles
     

    XML Style

      AJAX Tutorial
      XML Mobile
    Flash Tutorial/ Articles
     

    Flash Video

      Action Script
      Flash Articles
    OS Tutorial/ Articles
      Linux Tutorial
      Symbian Tutorial
      MacOS Tutorial
    Personal Tech
      Hardware Tutorial
      Software Tutorial
      Online Auction