db aware TimeSeries Line Chart

TeeChart VCL for Borland/CodeGear/Embarcadero RAD Studio, Delphi and C++ Builder.
Post Reply
CAC
Newbie
Newbie
Posts: 44
Joined: Tue Jun 20, 2006 12:00 am
Location: Plain City, Ohio
Contact:

db aware TimeSeries Line Chart

Post by CAC » Thu Nov 16, 2006 1:48 pm

I have a D7 App that allows users to retrieve groundwater levels measured in wells over long periods of time. The data is organized by well, date, and water level elevation. How do I permit users to graph more than one well at a time (many series) in the correct time series position (not all wells are measured on the same dates) on the fly?

Narcís
Site Admin
Site Admin
Posts: 14730
Joined: Mon Jun 09, 2003 4:00 am
Location: Banyoles, Catalonia
Contact:

Post by Narcís » Thu Nov 16, 2006 4:24 pm

Hi CAC,

You can set the date value to be the XValue in the series and set the bottom axis as DateTime as told in Tutorial 4 - Axis Control. You'll find the tutorials at TeeChart's program group.
Best Regards,
Narcís Calvet / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Image Image Image Image Image Image
Instructions - How to post in this forum

CAC
Newbie
Newbie
Posts: 44
Joined: Tue Jun 20, 2006 12:00 am
Location: Plain City, Ohio
Contact:

Post by CAC » Thu Nov 16, 2006 5:07 pm

I understand how to set the date value as the x-axis. What I need to do is figure out how TeeChart understands when it encounters a new well in my long list wells and then how it undertsands the new dates associated with those new wells. For example, how do I get 2 series (MW-01 and MW-02) out of this:

MW-01 10/23/55 567.89
MW-01 1/1/56 578.90
MW-01 5/4/56 578.40
MW-02 11/21/55 500.78
MW-02 1/15/56 502.34
MW-02 4/5/67 504.25

Marjan
Site Admin
Site Admin
Posts: 745
Joined: Fri Nov 07, 2003 5:00 am
Location: Slovenia
Contact:

Post by Marjan » Fri Nov 17, 2006 7:41 am

Hi.

I think you'll have to use the manual approach i.e. go through all values in table and create the necessary series and then populate them with values by using AddXY method. Pseudo code:

Code: Select all

var ser: TChartSeries;

With Table do
begin
  First;
  While Not(Eof) do
  begin
    // returns ser if ser.Title == Well value, otherwise nil
    ser = SeriesExists(ColumnByName('Well').AsString);
    if Not Assigned(ser) then ser := CreateNewSeries(ColumnByName('Well').AsString);
  // finally, add point to correct series
    ser.AddXY(ColumnByName('Data').AsString, ColumnByName('Data').AsDouble);
    Next;
  end;
end;
the SeriesExists function looks through all series in Chart.Series array and compares well value (string) with Chart.Series[index].Title. If match is found it returns Series[index], otherwise it returns nil. The CreateNewSeries founction adds new series to Chart and set it's (Series!) title to well value.
I know, it's not one-line-code, but it works and it gives you full control over the process.
Marjan Slatinek,
http://www.steema.com

CAC
Newbie
Newbie
Posts: 44
Joined: Tue Jun 20, 2006 12:00 am
Location: Plain City, Ohio
Contact:

Post by CAC » Mon Nov 27, 2006 2:47 am

I've tried the code you supplied, but with no luck. D7 doesn't seem to understand the "SeriesExists" function. What am I doing wong?

Marjan
Site Admin
Site Admin
Posts: 745
Joined: Fri Nov 07, 2003 5:00 am
Location: Slovenia
Contact:

Post by Marjan » Mon Nov 27, 2006 7:52 am

Hi.

SeriesExists function has to be coded (doesn't exists). The idea is to cycle through all chart series and if there is a match (series title is equal to "Well" column name, return series, otherwise return nil.). It's not too complicated at all:

Code: Select all

function SeriesExists(aChart: TCustomChart; ColName: String):TChartSeries;
begin
  result := nil;
  for i := 0 to aChart.SeriesCount-1 do
   if aChart.Series[i].Title = ColName then
   begin
      result := aChart.Series[i];
      break;
   end;
end;
The same (you have to code it yourself) goes for CreateNewSeries function:

Code: Select all

function CreateNewSeries(aChart: TCustomChart; ColName: String): TChartSeries;
begin
  result := TLineSeries.Create(aChart);
  result.Title := ColName;
  result.ParentChart := aChart;
end;
Marjan Slatinek,
http://www.steema.com

Post Reply