Recent

Author Topic: Multi Lineseries  (Read 12205 times)

mpknap

  • Full Member
  • ***
  • Posts: 155
Re: Multi Lineseries
« Reply #30 on: March 30, 2019, 03:34:40 pm »

Attachment


wp

  • Hero Member
  • *****
  • Posts: 13222
Re: Multi Lineseries
« Reply #31 on: March 30, 2019, 05:29:11 pm »
Why do you declare the variable which pick up the x value from the series as Integer? It is a TDateTime, i.e. a floating point value. The integer part of a TDateTime is the days only, the hours/minutes are lost because they are the fractional part. This is how it works:

Code: Pascal  [Select][+][-]
  1. procedure TForm1.ChartToolset1DataPointClickTool1AfterMouseDown(ATool: TChartTool;
  2.   APoint: TPoint);
  3. var
  4.   x: Double;
  5. begin
  6.   with ATool as TDatapointClickTool do
  7.     if (Series is TLineSeries) then
  8.       with TLineSeries(Series) do
  9.       begin
  10.         x := GetXValue(PointIndex);
  11.         Label3.Caption := title + ' ' +  FormatDateTime('ddddd hh:nn:ss', x);
  12.       end
  13.     else
  14.       Statusbar1.SimpleText := '';
  15. end;

mpknap

  • Full Member
  • ***
  • Posts: 155
Re: Multi Lineseries
« Reply #32 on: March 30, 2019, 05:50:28 pm »
That is the question why ... I changed it once and I forgot. :-[
 Thanks .

mpknap

  • Full Member
  • ***
  • Posts: 155
Re: Multi Lineseries
« Reply #33 on: April 08, 2019, 08:22:16 am »
Welcome back.
Until now, the graph showed the detection time and username.
I make a second chart, similar to the first one. It is supposed to show the detection time for a team in which there are many users. Works properly.
But I do not know how to do it by clicking on the point correctly showing the name of the team and the user of the particular detection.
Code: Pascal  [Select][+][-]
  1. procedure TForm4.Button3Click(Sender: TObject);
  2. const
  3.   BLOCK_SIZE = 1000;
  4. var
  5.   Detection: array{[1..15000]} of thit;
  6.   f: textfile;
  7.   d, i, j, y, z: integer;
  8.   ex, cc: int64;
  9.   plik, dir, xxx: string;
  10.   dt: tdatetime;
  11.   Users: TStringList;
  12. begin
  13.   Users := TStringList.Create;
  14.   Users.Duplicates := dupIgnore;
  15.   Users.Sorted := True;
  16.  
  17.   Chart1.ClearSeries;
  18.   dir := GetCurrentDir;
  19.   chdir(dir + '\DATA');
  20.   if FileExists(label6.Caption  ) =true then
  21.   begin
  22.  
  23.     plik := label6.Caption;
  24.     AssignFile(f, plik);
  25.     reset(f);
  26.     i := 0;
  27.     SetLength(Detection, 0);
  28.  
  29.     while not EOF(f) do
  30.     begin
  31.       if i mod BLOCK_SIZE = 0 then
  32.         SetLength(Detection, Length(Detection) + BLOCK_SIZE);
  33.  
  34.       readln(f,  Detection[i].time  );
  35.      
  36.       readln(f, Detection[i].lat );
  37.        
  38.       readln(f, Detection[i].long  );
  39.      
  40.       readln(f,  Detection[i].user_name  );
  41.      
  42.       readln(f, Detection[i].user_n  );
  43.  
  44.       readln(f,  Detection[i].team_name  );
  45.      
  46.  
  47.       readln(f, Detection[i].team_nr );
  48.  
  49.  
  50.       readln(f, xxx);
  51.      
  52.       Users.Add(Detection[i].team_nr);
  53.  
  54.       readln(f, xxx);
  55.       Inc(i);
  56.     end;
  57.     closefile(f);
  58.     SetLength(Detection, i);
  59.  
  60.    
  61.     SetLength(Series_ar, Users.Count);
  62.  
  63.     z := 0;
  64.     label4.Caption := i.ToString;
  65.      for j := 0 to Users.Count - 1 do
  66.  
  67.     begin
  68.       Series_ar[j] := TLineSeries.Create(Chart1);
  69.       Series_ar[j].ShowPoints := True;
  70.       Series_ar[j].Pointer.Brush.Color := rgb(Random(256), Random(256), Random(256));
  71.        Series_ar[j].Pointer.Pen.Color := clBlack;
  72.       Series_ar[j].Pointer.Style := psCircle;
  73.       Series_ar[j].Title := '';
  74.       Chart1.AddSeries(Series_ar[j]);
  75.     end;
  76.     d := 0;
  77.     for j := 0 to High(Detection) do
  78.     begin
  79.       d := Users.IndexOf(Detection[j].team_nr);
  80.       if d = -1 then
  81.         continue;
  82.         DT := unixToDateTime((Detection[j].time  div 1000));
  83.  
  84.      //Series_ar[d].AddXy(Detection[j].time, StrToInt(Detection[j].team_nr) );
  85.        Series_ar[d].AddXy( dt, StrToInt(Detection[j].team_nr));
  86.  
  87.        Series_ar[d].Title := (Detection[j].team_name+ Detection[j].User_name);{<---?????}
  88.    
  89.     end;
  90.     end;
  91.   chdir(dir);
  92.   Users.Free;
  93.  
  94. end;

I have also changed the format of the TXT file:
Time
Lat
Long
User Name
User Number
Team Name
Team Number
Free line - separator

wp

  • Hero Member
  • *****
  • Posts: 13222
Re: Multi Lineseries
« Reply #34 on: April 08, 2019, 10:48:38 am »
You could combine team and user name and add this string as a third parameter to the series' AddXY:
Code: Pascal  [Select][+][-]
  1. Series_ar[d].AddXX(
  2.   dt,                                              // x
  3.   StrToInt(Detection[j].team_nr),                  // y
  4.   Detection[j].team_name+ Detection[j].User_name   // text
  5. );
Then, in the click routine of the DataPointClickTool you extract that text and combine it with the date:
Code: Pascal  [Select][+][-]
  1.     procedure TForm1.ChartToolset1DataPointClickTool1AfterMouseDown(ATool: TChartTool;
  2.       APoint: TPoint);
  3.     var
  4.       x: Double;
  5.       s: String;
  6.     begin
  7.       with ATool as TDatapointClickTool do
  8.         if (Series is TLineSeries) then
  9.           with TLineSeries(Series) do
  10.           begin
  11.             x := GetXValue(PointIndex);
  12.             s := Source[PointIndex]^.Text;
  13.             Label3.Caption := s + ' ' +  DateTimeToStr(x);
  14.           end
  15.         else
  16.           Label3.Caption := '';
  17.     end;

mpknap

  • Full Member
  • ***
  • Posts: 155
Re: Multi Lineseries
« Reply #35 on: April 08, 2019, 07:56:16 pm »
Perfect!  ;)

mpknap

  • Full Member
  • ***
  • Posts: 155
Re: Multi Lineseries
« Reply #36 on: May 05, 2019, 05:51:42 pm »
A new problem WP.
How to count in each Series, how many detections are there in an identical timestamp (on x axis).
I want to show only those detections that occurred on several users at one time (+ -1 second).
I hope I wrote it clearly;)

 

TinyPortal © 2005-2018