Link to home
Start Free TrialLog in
Avatar of Vaalar
Vaalar

asked on

tdbchart and the label for maximum values

Hello Guys,
I have a database with data from scale. I make a chart which shows the production from one week and I would like to show the labels for maximum values of weight. Is it possible?
I mean the label on the top of every peak. By every peak I mean the max value of weight.
The x axis is weight and Y is date&time.
Now if i have 1000 records with weight i see every label on the diagram, or I can turn off all labels. You can imagine the mess on the diagram.
Best Regards
Vaalar
Avatar of SteveBay
SteveBay
Flag of United States of America image

If I understand your question correctly, I think you can accompilsh this by using the OnGetNextAxisLabel Event:
First you would have to find your highest value, This is a simple example:

procedure TForm1.DBChart1BeforeDrawAxes(Sender: TObject);
begin
     Table1.First;
     HighestValue := 0; // declared in the private section of the Form
     while not Table1.Eof do
          begin
          if HighestValue < Table1.FieldByName('Amount').AsInteger then
               HighestValue := Table1.FieldByName('Amount').AsInteger;
          Table1.Next;
          end;
end;

Then in the OnGetNextAxisLabel:

procedure TForm1.DBChart1GetNextAxisLabel(Sender: TChartAxis;  LabelIndex: Integer; var LabelValue: Double; var Stop: Boolean);
begin
    if Sender=DBChart1.LeftAxis then
     Begin
     // This will draw Labels at 200s and the Highest value
     if (LabelIndex mod 200 = 0) or (LabelIndex = HighestValue) then
          LabelValue := LabelIndex;
     End;
     Stop:=False;
end;
Avatar of Vaalar
Vaalar

ASKER

Hello Steve,
Thx for your help. I`m wondering is it possible to use ADOQuery1 for this issue. I will explain why:
As I said the data comes from scale, so if I choose the period of week I should receive 7 highest values on my chart. For example I`m choosing the range from 2008-10-06 to 2008-10-10 from 06:00:00 to 14:00:00, now I receive the chart of production.
I`m realizing this by this query:
'SELECT SUM(MASY_DZIEN.MASA_MAX)FROM (SELECT MAX(MASA) AS MASA_MAX FROM PRODUKCJA WHERE WAGA = :waga AND MASA BETWEEN :masa_od AND :masa_do AND DATA BETWEEN Convert(DateTime, :data_od) AND Convert(DateTime, :data_do)'+
        'AND CZAS >= Convert(DateTime, :czas_od) AND CZAS <= Convert(DateTime, :czas_do) GROUP BY convert(varchar(10), DATA, 105 )) masy_dzien'
Maybe there is a way to use my query and receive the max values in some kind of array.
I`m not sure becouse I`m newbe in Delphi and sql.
Best Regards
Vaalra
Are you saying that you will have 1000 records in your chart and you wish to only show a label for the highest value in each week?
Avatar of Vaalar

ASKER

no the highest value for every day in a week between 06:00:00 and 14:00:00
ASKER CERTIFIED SOLUTION
Avatar of SteveBay
SteveBay
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I dunno what database you are using but with oracle
you would LAG or LEAD in combination with MAX
LAG is analytic function and with it you could compare the current record to the previous one
detecting if you have an up slope or down slope
on the up slope you would then use the max function
this would then result in a field which is only filled in on the peak values