Board index » delphi » All I want, Bar Graph + Maybe a Line Graph

All I want, Bar Graph + Maybe a Line Graph

All I want to do is add a Bar Graph and a Line Graph into
my app to further illustrate some figures from a Database.

I have looked at the chart component but alway get frustrated
with it.  Anyone have some hints on how to achieve this or
an alternative chart component?

Jeremy

 

Re:All I want, Bar Graph + Maybe a Line Graph


Hi Jed +ACE-
There's a quick start guide with step by step instructions
on how to attach a database to a chart at TeeChart.hlp
help file  (located at c:+AFw-program files+AFw-delphi 3.0+AFw-help folder)
and at TeeChart manual in MsWord format tchartv3.doc
(located at ..+AFw-delphi 3.0+AFw-teechart folder)

You need to do this steps:

1) Place a TDBChart on Form1 (TDBChart is at +ACI-Data Controls+ACI-
component palette tab) .  Place a TTable or TQuery and connect
it to the database.

2) Double-click the chart. You'll see the Editor Dialog

3) Click on +ACI-Add...+ACI- to access the Gallery of chart types window.

4) Select a Line or Bar Series and click +ACI-Ok+ACI-.

5) Now you'll see a Bar chart, with random values
(these random values do not show at run-time, they show
only at design-time so you can see how it will look)

6) Now click on the +ACI-Series+ACI- tab on top of the dialog, or double-click
the +ACI-Series1+ACI- listbox item. This will show you the tabs with properties
for +ACI-Series1+ACI- (the Bar)

7) Now click on +ACI-DataSource+ACI- tab, and select +ACI-DataSet+ACI- from the
combobox in DataSource tab.

8) You'll have now access to your TTable or TQuery. Select it
on the +ACI-DataSet+ACI- combobox.

9) And finally select which fields from the dataset you want the
Bars to show. You can select an string field for the +ACI-Labels+ACI- and
a field for +ACI-Bars+ACI-.

10) Close the dialog. If the table or query is Active:+AD0-True, then
the DBChart should show the records at design-time.

All the above can be done also at run-time programatically, with
this code:

Uses DBChart, Series+ADs-

DBChart1.AddSeries( TBarSeries.Create(Self) )+ADs-
With DBChart1.Series+AFs-0+AF0- do
begin
  DataSource:+AD0-Table1+ADs-
  YValues.ValueSource:+AD0-'MyField'+ADs-
end+ADs-

Check the docs and run the TeeDemo.dpr example project
located at +AFw-delphi 3.0+AFw-demos+AFw-teechart folder. It has some
database examples for master-detail table relations, etc.
Check also our web site at http://www.teemach.com, where
you can download the +ACI-Technical Examples+ACI-.
The Pro version includes many more examples and the Pro
packages.
Best Regards +ACE-
David Berneda
www.teemach.com

Jed escribi+APM- en mensaje +ADw-64h02m+ACQ-s9j2+AEA-forums.borland.com+AD4-...
+AD4-All I want to do is add a Bar Graph and a Line Graph into
+AD4-my app to further illustrate some figures from a Database.
+AD4-
+AD4-I have looked at the chart component but alway get frustrated
+AD4-with it.  Anyone have some hints on how to achieve this or
+AD4-an alternative chart component?
+AD4-
+AD4-Jeremy
+AD4-
+AD4-

Re:All I want, Bar Graph + Maybe a Line Graph


OK thanks for the reply...
I have my database set up like this

MonthLabel    Jan
MonthNumber   1
Sales         675,000

etc.

How can I set it up to compare several years at once.
Like Jan 1996 to Jan 1997 and Jan 1998 etc?

Thanks for the other response.
What is the value of upgrading?

Jeremy

Quote
David Berneda wrote in message <64iec2$s...@forums.borland.com>...
>Hi Jed +ACE-
>There's a quick start guide with step by step instructions
>on how to attach a database to a chart at TeeChart.hlp
>help file  (located at c:+AFw-program files+AFw-delphi 3.0+AFw-help folder)
>and at TeeChart manual in MsWord format tchartv3.doc
>(located at ..+AFw-delphi 3.0+AFw-teechart folder)

>You need to do this steps:

>1) Place a TDBChart on Form1 (TDBChart is at +ACI-Data Controls+ACI-
>component palette tab) .  Place a TTable or TQuery and connect
>it to the database.

>2) Double-click the chart. You'll see the Editor Dialog

>3) Click on +ACI-Add...+ACI- to access the Gallery of chart types window.

>4) Select a Line or Bar Series and click +ACI-Ok+ACI-.

>5) Now you'll see a Bar chart, with random values
>(these random values do not show at run-time, they show
>only at design-time so you can see how it will look)

>6) Now click on the +ACI-Series+ACI- tab on top of the dialog, or
double-click
>the +ACI-Series1+ACI- listbox item. This will show you the tabs with
properties
>for +ACI-Series1+ACI- (the Bar)

>7) Now click on +ACI-DataSource+ACI- tab, and select +ACI-DataSet+ACI- from
the
>combobox in DataSource tab.

>8) You'll have now access to your TTable or TQuery. Select it
>on the +ACI-DataSet+ACI- combobox.

>9) And finally select which fields from the dataset you want the
>Bars to show. You can select an string field for the +ACI-Labels+ACI- and
>a field for +ACI-Bars+ACI-.

>10) Close the dialog. If the table or query is Active:+AD0-True, then
>the DBChart should show the records at design-time.

>All the above can be done also at run-time programatically, with
>this code:

>Uses DBChart, Series+ADs-

>DBChart1.AddSeries( TBarSeries.Create(Self) )+ADs-
>With DBChart1.Series+AFs-0+AF0- do
>begin
>  DataSource:+AD0-Table1+ADs-
>  YValues.ValueSource:+AD0-'MyField'+ADs-
>end+ADs-

>Check the docs and run the TeeDemo.dpr example project
>located at +AFw-delphi 3.0+AFw-demos+AFw-teechart folder. It has some
>database examples for master-detail table relations, etc.
>Check also our web site at http://www.teemach.com, where
>you can download the +ACI-Technical Examples+ACI-.
>The Pro version includes many more examples and the Pro
>packages.
>Best Regards +ACE-
>David Berneda
>www.teemach.com

>Jed escribi+APM- en mensaje

+ADw-64h02m+ACQ-s9j2+AEA-forums.borland.com+AD4-...

- Show quoted text -

Quote
>+AD4-All I want to do is add a Bar Graph and a Line Graph into
>+AD4-my app to further illustrate some figures from a Database.
>+AD4-
>+AD4-I have looked at the chart component but alway get frustrated
>+AD4-with it.  Anyone have some hints on how to achieve this or
>+AD4-an alternative chart component?
>+AD4-
>+AD4-Jeremy
>+AD4-
>+AD4-

Re:All I want, Bar Graph + Maybe a Line Graph


Using Line Graphs?

Jeremy

Re:All I want, Bar Graph + Maybe a Line Graph


Thanks for the response, what reader are you using the
reply has +ACE- and +ACI- all through it!!

Jeremy

Quote
David Berneda wrote in message <64p6l6$t...@forums.borland.com>...
>Hi Jeremy +ACE-
>You need a +ACI-Year+ACI- field in your table so you can make SQL queries

Re:All I want, Bar Graph + Maybe a Line Graph


Hi Jeremy +ACE-
See my previous message (the long message with step by
step instructions).
See item number 4), you can choose any Series type
you want: Line, Bar, Horizontal Bar, Area, Pie, Arrow, Bubble,
Gantt, etc, etc, etc.
Regards +ACE-
David

Jed escribi+APM- en mensaje +ADw-64l22o+ACQ-sqo6+AEA-forums.borland.com+AD4-...
+AD4-Using Line Graphs?
+AD4-
+AD4-Jeremy
+AD4-
+AD4-

Re:All I want, Bar Graph + Maybe a Line Graph


Hi Jeremy +ACE-
You need a +ACI-Year+ACI- field in your table so you can make SQL queries
to filter by the year field.
You can create one Chart Series (a Line, or a Bar, etc)
for each +ACI-Year+ACI-, and then assign to it an SQL query filtering
by the desired year value.

If you don't know in advance how many years can be in
the database, then you can use a more generic method
to auto-create Series.

In TeeChart Pro, one of the +ACI-extra+ACI- examples show how
to make a +ACI-group by+ACI- of a dataset and create several
series on-the-fly. (See below the code)

Delphi 3 Client/Server includes the DecisionCube and
DecisionGraph components which are very appropiate
for what you want to do.

You'll see all information and a list of differences between
TeeChart Standard and TeeChart Pro at our web site.
Regards +ACE-
David Berneda
www.teemach.com

+AHsAKgAqACoAKgAqACoAKgAqACoAKgAqACoAKgAqACoAKgAqACoAKgAqACoAKgAqACoAKgAqACoAKgAqACoAKgAqACoAKgAqACoAKgAqACoAKgAqACoAKgAqACoAKgB9-
+AHs-   TeeChart Cross-Tab routines                +AH0-
+AHs-   Copyright (c) 1996-97 by David Berneda     +AH0-
+AHsAKgAqACoAKgAqACoAKgAqACoAKgAqACoAKgAqACoAKgAqACoAKgAqACoAKgAqACoAKgAqACoAKgAqACoAKgAqACoAKgAqACoAKgAqACoAKgAqACoAKgAqACoAKgB9-
unit teeCross+ADs-
interface
uses DB,Chart,{*word*249}gine,TeeProcs+ADs-
type TGroupFormula+AD0-(gfCount,gfSum)+ADs-

+AHs- This procedure will create an array of Chart Series.
  The array is determined by the +ACI-AGroupField+ACI- parameter.
  The +ACI-ASeries+ACI- parameter will be used to duplicate it many times,
  one for each +ACI-group+ACI-.
  Example of use:
  ---------------
  Imagine you have a Table1 component with +ACI-product sales+ACI-.
  In this Table1 component you have the following fields:
  Product    ( Cars, Bikes, Trucks... )
  Country    ( USA, UK, Germany, Australia... )
  Amount     ( +ACQ-1234... )
  Now we want to create a Chart consisting of one Bar Series for
  each +ACI-Product+ACI-, showing the sum of +ACI-Amount+ACI- for each +ACI-Country+ACI-.
  So, our +ACI-GroupField+ACI- is +ACI-Product+ACI-, our +ACI-LabelField+ACI- is +ACI-Country+ACI- and
  our +ACI-ValueField+ACI- is +ACI-Amount+ACI-.
  The code is:
   ...
   begin
     FillDataSet( Table1, BarSeries1, +ACI-Product+ACI-, +ACI-Country+ACI-, +ACI-Amount+ACI-,
gfSum )+ADs-
   end+ADs-

  After calling this procedure, the Chart will own several Series, one for
  each +ACI-Product+ACI-.
  You can access and modify these Series as usually, like for example
  changing the Series Color, Title, etc.
+AH0-
Procedure FillDataSet( ADataSet:TDataSet+ADs-
                       ASeries:TChartSeries+ADs-
                       Const AGroupField,ALabelField,AValueField:String+ADs-
                       GroupFormula:TGroupFormula)+ADs-
implementation

Procedure FillDataSet( ADataSet:TDataSet+ADs-
                       ASeries:TChartSeries+ADs-
                       Const AGroupField,ALabelField,AValueField:String+ADs-
                       GroupFormula:TGroupFormula)+ADs-
   Function LocateSeries(Const ATitle:String):TChartSeries+ADs-
   var t:Integer+ADs-
   begin
     With ASeries.ParentChart do
     for t:+AD0-0 to SeriesCount-1 do
     if Series+AFs-t+AF0-.Title+AD0-ATitle then
     begin
       result:+AD0-Series+AFs-t+AF0AOw-
       exit+ADs-
     end+ADs-
     result:+AD0-nil+ADs-
   end+ADs-
   Function LocateLabel(tmpSeries:TChartSeries+ADs- Const
ALabel:String):Integer+ADs-
   var t:Integer+ADs-
   begin
     With tmpSeries do
     for t:+AD0-0 to Count-1 do
     if XLabel+AFs-t+AF0APQ-ALabel then
     begin
       result:+AD0-t+ADs-
       exit+ADs-
     end+ADs-
     result:+AD0--1+ADs-
   end+ADs-
var tmpGroup:String+ADs-
    tmpSeries:TChartSeries+ADs-
    tmpLabel:String+ADs-
    tmpValue:Double+ADs-
    t,tt,
    tmpPoint:Integer+ADs-
begin
  With ASeries.ParentChart do
  begin
    While SeriesCount+AD4-1 do
          if Series+AFs-SeriesCount-1+AF0APAA+-ASeries then Series+AFs-SeriesCount-1+AF0-.Free+ADs-
    ASeries.Clear+ADs-
    ASeries.Title:+AD0-''+ADs-
    With ADataSet do
    begin
      DisableControls+ADs-
      try
        First+ADs-
        While not eof do
        begin
          tmpGroup:+AD0-FieldByName(AGroupField).AsString+ADs-
          tmpSeries:+AD0-LocateSeries(tmpGroup)+ADs-
          if tmpSeries+AD0-nil then
          begin
            if ASeries.Title+AD0-'' then
               tmpSeries:+AD0-ASeries
            else
            begin
              tmpSeries:+AD0-CloneChartSeries(ASeries)+ADs-
              tmpSeries.SeriesColor:+AD0-GetDefaultColor(SeriesCount)+ADs-
            end+ADs-
            tmpSeries.Title:+AD0-tmpGroup+ADs-
          end+ADs-
          tmpLabel:+AD0-FieldByName(ALabelField).AsString+ADs-
          tmpValue:+AD0-FieldByName(AValueField).AsFloat+ADs-
          if GroupFormula+AD0-gfCount then tmpValue:+AD0-1+ADs-
          tmpPoint:+AD0-LocateLabel(tmpSeries,tmpLabel)+ADs-
          if tmpPoint+AD0--1 then
          begin
            tmpSeries.Add(tmpValue,tmpLabel,clTeeColor)+ADs-
            for t:+AD0-0 to SeriesCount-1 do
            if Series+AFs-t+AF0APAA+-tmpSeries then
               if tmpSeries.Count+AD4-Series+AFs-t+AF0-.Count then
               for tt:+AD0-1 to (tmpSeries.Count-Series+AFs-t+AF0-.Count) do
                   Series+AFs-t+AF0-.Add(0,tmpLabel,clTeeColor)+ADs-
          end
          else
          begin
            With tmpSeries.MandatoryValueList do
            case GroupFormula of
              gfCount,
              gfSum: Value+AFs-tmpPoint+AF0-:+AD0-Value+AFs-tmpPoint+AF0AKw-tmpValue+ADs-
            end+ADs-
          end+ADs-
          Next+ADs-
        end+ADs-
      finally
        EnableControls+ADs-
      end+ADs-
    end+ADs-
  end+ADs-
end+ADs-
end.

Jed escribi+APM- en mensaje +ADw-64kukf+ACQ-sq43+AEA-forums.borland.com+AD4-...
+AD4-OK thanks for the reply...
+AD4-I have my database set up like this
+AD4-
+AD4-MonthLabel    Jan
+AD4-MonthNumber   1
+AD4-Sales         675,000
+AD4-
+AD4-etc.
+AD4-
+AD4-How can I set it up to compare several years at once.
+AD4-Like Jan 1996 to Jan 1997 and Jan 1998 etc?
+AD4-
+AD4-Thanks for the other response.
+AD4-What is the value of upgrading?
+AD4-
+AD4-Jeremy
+AD4-

Other Threads