Page 1 of 1

db aware TimeSeries Line Chart

Posted: Thu Nov 16, 2006 1:48 pm
by 9241637
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?

Posted: Thu Nov 16, 2006 4:24 pm
by narcis
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.

Posted: Thu Nov 16, 2006 5:07 pm
by 9241637
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

Posted: Fri Nov 17, 2006 7:41 am
by Marjan
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.

Posted: Mon Nov 27, 2006 2:47 am
by 9241637
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?

Posted: Mon Nov 27, 2006 7:52 am
by Marjan
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;