Solved

tdbchart and the label for maximum values

Posted on 2008-10-08
6
432 Views
Last Modified: 2013-11-23
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
0
Comment
Question by:Vaalar
  • 3
  • 2
6 Comments
 
LVL 14

Expert Comment

by:SteveBay
ID: 22681778
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;
0
 

Author Comment

by:Vaalar
ID: 22685112
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
0
 
LVL 14

Expert Comment

by:SteveBay
ID: 22686883
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?
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

Author Comment

by:Vaalar
ID: 22687109
no the highest value for every day in a week between 06:00:00 and 14:00:00
0
 
LVL 14

Accepted Solution

by:
SteveBay earned 500 total points
ID: 22687408
Ok. I think you are right that you could do it with a Query. I am not as good at SQL as I am with Delphi :).
Perhaps some thing like this:
//....

  private

    { Private declarations }

     HighValues : TList;

  public

    { Public declarations }

  end;
 

var

  Form1: TForm1;
 

implementation
 

{$R *.dfm}
 

procedure TForm1.FormShow(Sender: TObject);

begin

     HighValues := TList.Create;

end;

procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);

begin

     HighValues.Free;

end;
 

procedure TForm1.DBChart1GetNextAxisLabel(Sender: TChartAxis;

  LabelIndex: Integer; var LabelValue: Double; var Stop: Boolean);

begin

    if Sender=DBChart1.LeftAxis then

     Begin

     if ( HighValues.IndexOf(Pointer(LabelIndex)) > -1 ) then

          LabelValue := LabelIndex;

     End;

     Stop:=False;

end;
 

procedure TForm1.DBChart1BeforeDrawAxes(Sender: TObject);

var Weight, DOW : Integer;
 

begin

     HighValues.Clear;

     for DOW := 0 to 6 do

          HighValues.Add(pointer(0));
 

     Table1.First;

     while not Table1.Eof do

          begin

          DOW := DayOfWeek(Table1.FieldByName('Date').AsDateTime) - 1;

          Weight := Table1.FieldByName('Weight').AsInteger;

          if Integer(HighValues[DOW]) <  Weight then

               HighValues[DOW] := Pointer(Weight);

          Table1.Next;

          end;

end;

Open in new window

0
 
LVL 36

Expert Comment

by:Geert Gruwez
ID: 22687425
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
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Delphi cmd execution 6 40
Internet Explorer View Settings Question 15 99
LAN or WAN ? 11 63
Multiple image collision 13 45
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now