Icon View Thread

The following is the text of the current message along with any replies.
Messages 1 to 4 of 4 total
Thread create a series in a chart according to SQL statement
Sun, Apr 27 2008 4:27 AMPermanent Link

Khaled Homouda
I need to chart accounts where it might span the same month in different
years i.e. 1/2007 and 3/2008, if one bar series is used, it makes both months
in the same bar position, what if I need to extract different months and let every
year be represented in a different series to be charted stacked behind each
other...
this is my code. I am thinking to make a while loop (from one year to another year) and use the select statement inside the while loop grouping by the
month of the year assigned in the while loop. Every loop I create a new series, but frankly I can't do it, as getting the no of years (thought of using: YearsBetween(YearFirst, YearLast), and creating the
series (because to create a series I should declare a variable by a name..so how to increment?).
Can somebody help me? thanks

  BarSeries1.Clear ;
  With ChrtQry do begin
  Close ;
  SQL.Clear ;
  SQL.Add('SELECT SUM(' +TabName+ '.Paid) AS SumPaid, ') ;
  SQL.Add('EXTRACT(MONTH FROM ' +TabName+ '.Date) AS MonthNo', EXTRACT(YEAR FROM ' +TabName+ '.Date) AS YearNo') ;
  If Total and FirstSQL then SQL.Add('INTO Temp ') ;
  SQL.Add('FROM ' +TabName) ;
  SQL.Add('WHERE ' +TabName+ '.Date BETWEEN '+
QuotedStr(AnsiDateToStr(DTPFrom.Date))+ ' AND '
+QuotedStr(AnsiDateToStr(DTPTo.Date)) );
  SQL.Add('Group By MonthNo, YearNo') ;

  With BarSeries1 do
    begin
     ParentChart:=BarChart;
     DataSource:=ChrtQry;
     YValues.ValueSource:= 'SumPaid';
     XValues.ValueSource:= 'MonthNo';
     XLabelsSource := 'MonthNo' ;
     Marks.Brush.Style := bsClear ;
     Marks.Color := clWhite ;
     Marks.Frame.Visible := False ;
     Marks.Style := smsValue ;
     Marks.Visible := True  ;
     CheckDatasource;
    end ;
  Open ;
  end ;
Sun, Apr 27 2008 12:11 PMPermanent Link

Fernando Dias

Team Elevate Team Elevate

Khaled,

I assume you are using TeeChar, which I'm not familiar with, but here
are some suggestions:
You may put you code inside a loop as you said, but for that to work you
must dynamically create a series (TBarSeries) and a dataset
(TDBISAMQuery) for each iteration (year).
You can create a series object with TBarSeries.Create method and the
datasets with TDBISAMQuery.Create method, and don't forget you must
destroy all the objects you create somehow later in your code.

--
Fernando Dias
[Team Elevate]
Mon, Apr 28 2008 5:43 PMPermanent Link

Khaled Homouda
Thanks Fernando
I am a bit confused of 2 things how do I get the year numbers off 2 dates and the ones between and if I create a series inside a loop don't I have to name a variable in the var section before the begin
and in doing so how many variables to declare, excuse me being novice
Mon, Apr 28 2008 9:26 PMPermanent Link

Fernando Dias

Team Elevate Team Elevate

Khaled,

Since I'm not familiar with TeeChart, I decided to try it to see if I
can use it in my own projects. You can find an example app in binaries
(Delphi 2006) that I believe will help you.

--
Fernando Dias
[Team Elevate]
Image