Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- unit Unit1;
- interface
- uses
- {$IFDEF MSWINDOWS}
- WinApi.Windows, WinApi.Messages,
- {$ENDIF}
- System.SysUtils, System.Types, System.UITypes, System.UIConsts, System.Classes,
- System.Variants, System.JSON, System.IOUtils, System.Math, System.Rtti,
- FMX.Types, FMX.Controls, FMX.Objects, FMX.Forms, FMX.Layouts, FMX.Menus,
- FMX.Graphics, FMX.Dialogs, FMX.StdCtrls, FMX.Styles.Objects,
- FMX.Controls.Presentation, FMX.Edit, FMX.ScrollBox, FMX.Memo,
- FMXTee.Engine, FMXTee.Procs, FMXTee.Chart, FMXTee.Series, FMXTee.Tools,
- FMXTee.Tools.SubChart, unFileMapping;
- type
- TDataStruct = Record
- deviceId : Integer;
- datetime : TDateTime;
- field0 : Integer;
- field1 : Single;
- field2 : Single;
- field3 : Single;
- field4 : SmallInt;
- end;
- type
- TDataStructArray = array[0..MaxInt div SizeOf(TDataStruct) - 1] of TDataStruct;
- PDataStructArray = ^TDataStructArray;
- type
- TForm1 = class(TForm)
- FramedVertScrollBox1: TFramedVertScrollBox;
- Chart1: TChart;
- Chart1Series0: TFastLineSeries;
- Chart1Series1: TFastLineSeries;
- Chart1Series2: TFastLineSeries;
- Chart2: TChart;
- Chart2Series0: TFastLineSeries;
- Chart2Series1: TFastLineSeries;
- Chart3: TChart;
- Chart3Series0: TFastLineSeries;
- Chart3Series1: TFastLineSeries;
- Chart4: TChart;
- Chart4Series0: TFastLineSeries;
- Chart5: TChart;
- Series1b: TFastLineSeries;
- Series2b: TFastLineSeries;
- Series3b: TFastLineSeries;
- Label1: TLabel;
- Label2: TLabel;
- Label3: TLabel;
- Label4: TLabel;
- Label5: TLabel;
- Label6: TLabel;
- Label7: TLabel;
- ScrollBar1: TScrollBar;
- Button1: TButton;
- Button2: TButton;
- Button3: TButton;
- Button4: TButton;
- procedure FormCreate(Sender: TObject);
- procedure RectClick(Sender:TAnnotationTool; Button:TMouseButton; Shift: TShiftState; X, Y: Integer);
- procedure Chart1KeyDown(Sender: TObject; var Key: Word; var KeyChar: Char;
- Shift: TShiftState);
- procedure ScrollBar1Change(Sender: TObject);
- procedure Chart1MouseUp(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Single);
- procedure Chart1MouseMove(Sender: TObject; Shift: TShiftState; X,
- Y: Single);
- procedure Chart5MouseMove(Sender: TObject; Shift: TShiftState; X,
- Y: Single);
- procedure Chart5MouseDown(Sender: TObject; Button: TMouseButton;
- Shift: TShiftState; X, Y: Single);
- private
- { Private declarations }
- sbIncremental: Single;
- FDragging: boolean;
- public
- { Public declarations }
- end;
- var
- Form1: TForm1;
- seleRectChart1 : TRectangleTool;
- seleRectChart2 : TRectangleTool;
- seleRectChart3 : TRectangleTool;
- seleRectChart4 : TRectangleTool;
- seleRectChart5 : TRectangleTool;
- DataFile : TMappedFile;
- Datas: PDataStructArray;
- FDragging: boolean;
- DifX, DifY: Integer;
- OrigXPos: Integer;
- implementation
- {$R *.fmx}
- procedure TForm1.FormCreate(Sender: TObject);
- begin
- DataFile := TMappedFile.Create(ExpandFileName(IncludeTrailingPathDelimiter(ExtractFilePath(ParamStr(0)) + '..\..')) + 'TeeChart.dat');
- sbIncremental := -256;
- Form1.Position := TFormPosition.ScreenCenter; //poScreenCenter
- ScrollBar1.Max := 10;
- ScrollBar1.Min := -10;
- ScrollBar1.Value := 0;
- With Chart1 do begin
- Color := TAlphaColors.Black;
- Title.Caption := ''; //.Text.Strings
- AllowPanning := pmHorizontal; //permit manual scrolling horizontally only.
- Axes.Bottom.Automatic := False;
- Axes.Bottom.Maximum := 250;
- Axes.Bottom.Minimum := 2;
- LeftAxis.Automatic := True;
- LeftAxis.AutomaticMaximum := True;
- LeftAxis.AutomaticMinimum := True;
- LeftAxis.AxisValuesFormat := '#,##0.#';
- LeftAxis.LabelsFormat.Font.Color := TAlphaColors.Red; //xFFCF3F3F;
- LeftAxis.Maximum := 42.500000000000000000;
- LeftAxis.Minimum := -0.500000000000000000;
- LeftAxis.Title.Caption := 'Chart1';
- LeftAxis.Title.Font.Color := TAlphaColors.Red; //claRed RGB(256, 0, 0)
- LeftAxis.Title.Font.Brush.Color := TAlphaColors.Red; //TColor($FFFFFF) claRed
- Zoom.Allow := True;
- end;
- seleRectChart1 := TRectangleTool.Create(self);
- Chart1.Tools.Add(seleRectChart1);
- with (Chart1.Tools[0] as TRectangleTool) do //
- begin
- Text := 'Rectangle Tool 1';
- AllowDrag := False;
- AutoSize := True;
- Shape.Color := $00FFFFFF;
- Shape.Font.Color := TAlphaColors.Green;
- Shape.Pen.Color := TAlphaColors.Red;
- Shape.Transparency := 0;
- Left := 100; // 55 (Sender as TChart).Zoom.X0 100;
- Top := 5; // (Sender as TChart).Zoom.Y0 75;
- Width := 50; //Round((Sender as TChart).Zoom.X1 - (Sender as TChart).Zoom.X0 ) Chart5.Width Zoom.X1
- Height := Round(Chart1.Height - 10); //Zoom.Y1
- OnClick := RectClick;
- OnKeyDown := Chart1KeyDown;
- end;
- With Chart2 do begin
- Color := TAlphaColors.Black;
- Title.Caption := '';
- AllowPanning := pmHorizontal; //permit manual scrolling horizontally only.
- Axes.Bottom.Automatic := False;
- Axes.Bottom.Maximum := 250;
- Axes.Bottom.Minimum := 2;
- LeftAxis.Automatic := True;
- LeftAxis.AutomaticMaximum := True;
- LeftAxis.AutomaticMinimum := True;
- LeftAxis.AxisValuesFormat := '#,##0.#';
- LeftAxis.LabelsFormat.Font.Color := TAlphaColors.Blue;
- LeftAxis.Maximum := 99.500000000000000000;
- LeftAxis.Minimum := -0.500000000000000000;
- LeftAxis.Title.Caption := 'Chart2'; // ยตS / uS
- LeftAxis.Title.Font.Color := TAlphaColors.Blue; //00FACE87 claLightskyblue RGB(256, 0, 0)
- LeftAxis.Title.Font.Brush.Color := TAlphaColors.Blue; //claLightskyblue
- Zoom.Allow := True;
- end;
- seleRectChart2 := TRectangleTool.Create(self);
- Chart2.Tools.Add(seleRectChart2);
- with (Chart2.Tools[0] as TRectangleTool) do
- begin
- Text := 'Rectangle Tool 2';
- AllowDrag := False;
- AutoSize := True;
- Shape.Color := $00FFFFFF;
- Shape.Font.Color := TAlphaColors.Green;
- Shape.Pen.Color := TAlphaColors.Blue;
- Shape.Transparency := 0;
- Left := 100; // Chart2.Zoom.X0 100;
- Top := 5; // Chart2.Zoom.Y0 75;
- Width := 50; //Round(Chart2.Width - 76); // Chart2.Zoom.X1
- Height := Round(Chart2.Height - 10); // Chart2.Zoom.Y1
- //Shape.Brush.Style := bsClear;
- OnClick := RectClick;
- OnKeyDown := Chart1KeyDown;
- end;
- With Chart3 do begin
- Color := TAlphaColors.Black;
- Title.Caption := '';
- AllowPanning := pmHorizontal; //permit manual scrolling horizontally only.
- Axes.Bottom.Automatic := False;
- Axes.Bottom.Maximum := 250;
- Axes.Bottom.Minimum := 2;
- LeftAxis.Automatic := True;
- LeftAxis.AutomaticMaximum := True;
- LeftAxis.AutomaticMinimum := True;
- LeftAxis.AxisValuesFormat := '#,##0.#';
- LeftAxis.LabelsFormat.Font.Color := TAlphaColors.Green;
- LeftAxis.Maximum := 12.500000000000000000;
- LeftAxis.Minimum := -0.500000000000000000;
- LeftAxis.Title.Caption := 'Chart3'; // lb
- LeftAxis.Title.Font.Color := TAlphaColors.Green; //00FACE87 claLightskyblue RGB(256, 0, 0)
- LeftAxis.Title.Font.Brush.Color := TAlphaColors.Green; //claLightskyblue
- Zoom.Allow := True;
- end;
- seleRectChart3 := TRectangleTool.Create(self);
- Chart3.Tools.Add(seleRectChart3);
- with (Chart3.Tools[0] as TRectangleTool) do
- begin
- Text := 'Rectangle Tool 3';
- AllowDrag := False;
- AutoSize := True;
- Shape.Color := $00FFFFFF;
- Shape.Font.Color := TAlphaColors.Green;
- Shape.Pen.Color := TAlphaColors.Green;
- Shape.Transparency := 0;
- Left := 100; // (Sender as TChart).Zoom.X0 100;
- Top := 5; // (Sender as TChart).Zoom.Y0 75;
- Width := 50; // Round(Chart3.Width - 76); //Zoom.X1
- Height := Round(Chart3.Height - 10); //Zoom.Y1
- //Shape.Brush.Style := bsClear;
- OnClick := RectClick;
- OnKeyDown := Chart1KeyDown;
- end;
- With Chart4 do begin
- Color := TAlphaColors.Black;
- Title.Caption := '';
- AllowPanning := pmHorizontal; //permit manual scrolling horizontally only.
- Axes.Bottom.Automatic := False;
- Axes.Bottom.Maximum := 250;
- Axes.Bottom.Minimum := 2;
- LeftAxis.Automatic := True;
- LeftAxis.AutomaticMaximum := True;
- LeftAxis.AutomaticMinimum := True;
- LeftAxis.AxisValuesFormat := '#,##0.#';
- LeftAxis.LabelsFormat.Font.Color := TAlphaColors.Purple;
- LeftAxis.Maximum := 12.500000000000000000;
- LeftAxis.Minimum := -0.500000000000000000;
- LeftAxis.Title.Caption := 'Chart4';
- LeftAxis.Title.Font.Color := TAlphaColors.Purple; //00FACE87 claLightskyblue RGB(256, 0, 0)
- LeftAxis.Title.Font.Brush.Color := TAlphaColors.Purple; //claLightskyblue
- Zoom.Allow := True;
- end;
- seleRectChart4 := TRectangleTool.Create(self);
- Chart4.Tools.Add(seleRectChart4);
- with (Chart4.Tools[0] as TRectangleTool) do
- begin
- Text := 'Rectangle Tool 4';
- AllowDrag := False;
- AutoSize := True;
- Shape.Color := $00FFFFFF;
- Shape.Font.Color := TAlphaColors.Green;
- Shape.Pen.Color := TAlphaColors.Purple;
- Shape.Transparency := 0;
- Left := 100; // (Sender as TChart).Zoom.X0 100;
- Top := 5; // (Sender as TChart).Zoom.Y0 75;
- Width := 50; //Round(Chart4.Width - 76); //Zoom.X1
- Height := Round(Chart4.Height - 10); //Zoom.Y1
- OnClick := RectClick;
- OnKeyDown := Chart1KeyDown;
- end;
- With Chart5 do begin
- Color := TAlphaColors.White;
- Title.Caption := '';
- AllowPanning := pmHorizontal; //permit manual scrolling horizontally only.
- Axes.Bottom.Automatic := True;
- Axes.Bottom.Maximum := 250;
- Axes.Bottom.Minimum := 2;
- LeftAxis.Automatic := True;
- LeftAxis.AutomaticMaximum := True;
- LeftAxis.AutomaticMinimum := True;
- LeftAxis.AxisValuesFormat := '#,##0.#';
- LeftAxis.LabelsFormat.Font.Color := TAlphaColors.Black;
- LeftAxis.Maximum := 12.500000000000000000;
- LeftAxis.Minimum := -0.500000000000000000;
- LeftAxis.Title.Caption := 'Chart5';
- LeftAxis.Title.Font.Color := TAlphaColors.Black; //00FACE87 claLightskyblue RGB(256, 0, 0)
- LeftAxis.Title.Font.Brush.Color := TAlphaColors.Black; //claLightskyblue
- Zoom.Allow := True;
- end;
- ScrollBar1.BeginUpdate;
- ScrollBar1.Value := -1;
- ScrollBar1.EndUpdate;
- ScrollBar1.Repaint;
- end;
- procedure TForm1.RectClick(Sender:TAnnotationTool; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
- begin
- if Button=TMouseButton.mbRight then
- begin
- with Chart1.Tools.Add(TRectangleTool) as TRectangleTool do
- begin
- Text:=Sender.Text + ' (twin)';
- AutoSize:=Sender.AutoSize;
- Shape.Color := Sender.Shape.Color;
- Shape.Transparency:=Sender.Shape.Transparency;
- Top:=Sender.Top+Sender.Height;
- Left:=Sender.Left;
- OnClick:=RectClick;
- end;
- end else if Button=TMouseButton.mbLeft then
- begin
- {
- if Assigned(selectedRect) then
- selectedRect.Shape.Pen.Color:=TAlphaColors.Black;
- selectedRect:=Sender as TRectangleTool;
- selectedRect.Shape.Pen.Color:=TAlphaColors.Red;
- }
- end;
- end;
- procedure TForm1.Chart1KeyDown(Sender: TObject; var Key: Word;
- var KeyChar: Char; Shift: TShiftState);
- begin
- if Key=VK_DELETE then
- if seleRectChart1 <> nil then
- begin
- Chart1.Tools.Remove(seleRectChart1);
- Chart1.Repaint;
- end;
- end;
- procedure TForm1.ScrollBar1Change(Sender: TObject);
- var
- sb: TScrollBar;
- sbOnChange: TNotifyEvent;
- i: Integer;
- begin
- sb := (Sender as TScrollBar);
- Chart1Series0.Clear;
- Chart1Series1.Clear;
- Chart1Series2.Clear;
- Chart2Series0.Clear;
- Chart2Series1.Clear;
- Chart3Series0.Clear;
- Chart3Series1.Clear;
- Chart4Series0.Clear;
- Series1b.Clear;
- Series2b.Clear;
- Series3b.Clear;
- Chart1.UndoZoom;
- Chart2.UndoZoom;
- Chart3.UndoZoom;
- Chart4.UndoZoom;
- Chart5.UndoZoom;
- try
- if DataFile = nil then
- DataFile := TMappedFile.Create(ExpandFileName(IncludeTrailingPathDelimiter(ExtractFilePath(ParamStr(0)) + '..\..')) + 'TeeChart.dat');
- Datas := PDataStructArray(DataFile.Content); // not needed, but handy
- if (DataFile.Size div SizeOf(TDataStruct) - 1 + Round(sbIncremental)) >= 0 then begin
- for i := (DataFile.Size div SizeOf(TDataStruct) - 1 + Round(sbIncremental)) to DataFile.Size div SizeOf(TDataStruct) - 1 do begin
- if (DataFile.Size div SizeOf(TDataStruct) - 1) <> 1 then begin
- Chart1Series0.AddY(Datas[i].field1);
- Series1b.AddY(Round(Datas[i].field1));
- Chart2Series0.AddY(Round(Datas[i].field2));
- Series2b.AddY(Round(Datas[i].field2));
- Chart3Series0.AddY(Round(Datas[i].field3));
- Series3b.AddY(Round(Datas[i].field3));
- Chart4Series0.AddY(Datas[i].field4);
- end;
- end;
- sbIncremental := sbIncremental + sb.Value;
- end else
- sbIncremental := -abs(DataFile.Size div SizeOf(TDataStruct) - 1);
- finally
- //DataFile.Free;
- end;
- sbOnChange := sb.OnChange; // Disable OnChange event
- sb.OnChange := nil; // -"-
- // sb.Value := (sb.Min + sb.Max) / 2; // Reset position
- sb.OnChange := sbOnChange; // Re-enable OnChange event
- Label2.Text := FloatToStr(sbIncremental);
- Label4.Text := IntToStr(Round(sbIncremental));
- FDragging := True;
- if sbIncremental < 0 then
- begin
- if FDragging then
- begin
- with (Chart1.Tools[0] as TRectangleTool) do
- begin
- Shape.Left := Round(DifX) - 1; //X-
- Shape.Top := 0;
- Shape.Width := Round(DifX) - 1;
- end;
- with (Chart2.Tools[0] as TRectangleTool) do
- begin
- Shape.Left := Round(DifX) - 1; //X-
- Shape.Top := 0;
- Shape.Width := Round(DifX) - 1;
- end;
- with (Chart3.Tools[0] as TRectangleTool) do
- begin
- Shape.Left := Round(DifX) - 1; //X-
- Shape.Top := 0;
- Shape.Width := Round(DifX) - 1;
- end;
- with (Chart4.Tools[0] as TRectangleTool) do
- begin
- Shape.Left := Round(DifX) - 1; //X-
- Shape.Top := 0;
- Shape.Width := Round(DifX) - 1;
- end;
- end;
- end;
- //FDragging := False;
- end;
- procedure TForm1.Chart1MouseUp(Sender: TObject; Button: TMouseButton;
- Shift: TShiftState; X, Y: Single);
- begin
- FDragging := False;
- end;
- procedure TForm1.Chart1MouseMove(Sender: TObject; Shift: TShiftState; X,
- Y: Single);
- var
- SeriesIndex: Integer;
- begin
- SeriesIndex := Chart1Series0.Clicked(X, Y);
- Chart1.ShowHint := SeriesIndex <> -1;
- if Chart1.ShowHint = True then begin
- Chart1.Hint := 'Y Axis: ' + FloatToStr(Chart1.LeftAxis.CalcPosPoint(Round(Y))); // SeriesIndex
- end;
- end;
- procedure TForm1.Chart5MouseMove(Sender: TObject; Shift: TShiftState; X,
- Y: Single);
- begin
- if FDragging then
- begin
- with (Chart1.Tools[0] as TRectangleTool) do
- begin
- Shape.Top := 0+5;
- //Was the Button is preesed
- if GetKeyState(VK_LBUTTON) < 0 then
- begin
- DifX := Round(X-Shape.Left);
- DifY := Round(Y-Shape.Top);
- Shape.Left := OrigXPos; //Round(DifX)
- Shape.Width := Round(DifX); //-X
- Label5.Text := 'DifX: ' + IntToStr(Round(DifX));
- Label6.Text := 'OrigXPos: ' + IntToStr(OrigXPos);
- Label7.Text := 'X: ' + IntToStr(Round(X));
- Repaint;
- end;
- end;
- with (Chart2.Tools[0] as TRectangleTool) do
- begin
- Shape.Top := 0+5;
- //Was the Button is preesed
- if GetKeyState(VK_LBUTTON) < 0 then
- begin
- DifX := Round(X-Shape.Left);
- DifY := Round(Y-Shape.Top);
- Shape.Left := OrigXPos; //Round(DifX)
- Shape.Width := Round(DifX); //-X
- Repaint;
- end;
- end;
- with (Chart3.Tools[0] as TRectangleTool) do
- begin
- Shape.Top := 0+5;
- //Was the Button is preesed
- if GetKeyState(VK_LBUTTON) < 0 then
- begin
- DifX := Round(X-Shape.Left);
- DifY := Round(Y-Shape.Top);
- Shape.Left := OrigXPos; //Round(DifX)
- Shape.Width := Round(DifX); //-X
- Repaint;
- end;
- end;
- with (Chart4.Tools[0] as TRectangleTool) do
- begin
- Shape.Top := 0+5;
- //Was the Button is preesed
- if GetKeyState(VK_LBUTTON) < 0 then
- begin
- DifX := Round(X-Shape.Left);
- DifY := Round(Y-Shape.Top);
- Shape.Left := OrigXPos; //Round(DifX)
- Shape.Width := Round(DifX); //-X
- Repaint;
- end;
- end;
- end;
- end;
- procedure TForm1.Chart5MouseDown(Sender: TObject; Button: TMouseButton;
- Shift: TShiftState; X, Y: Single);
- begin
- {
- The following code disables the OnZoom event from executing the
- function code. H/e it still continues to execute the zooming
- feature through teecharts, making it pointless and useless,
- unless the intent is to disable user-defined functions
- for Chart5OnZoom(), then it works great!
- }
- // cz: FMXTee.Chart.TChart; // TCustomChart TTeeChart FMXTee.Procs TChart.Zoom
- // czOnZoom: TNotifyEvent;
- // ------
- // cz := (Sender as FMXTee.Chart.TChart); //TChart TCustomChart
- // czOnZoom := cz.OnZoom; // Disable OnZoom event
- // cz.OnZoom := nil;
- // cz.OnZoom := czOnZoom; // Re-enable OnZoom event
- with (Chart1.Tools[0] as TRectangleTool) do
- //if Clicked(Round(X),Round(Y)) = True then
- begin
- DifX := Round(X-Shape.Left);
- DifY := Round(Y-Shape.Top);
- OrigXPos := Round(X); //Round(Chart1.Axes.Bottom.CalcPosPoint(Round(X)));
- //ShowMessage('OrigXPos: ' + IntToStr(OrigXPos));
- end;
- with (Chart2.Tools[0] as TRectangleTool) do
- //if Clicked(Round(X),Round(Y)) = True then
- begin
- DifX := Round(X-Shape.Left);
- DifY := Round(Y-Shape.Top);
- OrigXPos := Round(X); //Round(Chart1.Axes.Bottom.CalcPosPoint(Round(X)));
- end;
- with (Chart3.Tools[0] as TRectangleTool) do
- //if Clicked(Round(X),Round(Y)) = True then
- begin
- DifX := Round(X-Shape.Left);
- DifY := Round(Y-Shape.Top);
- OrigXPos := Round(X); //Round(Chart1.Axes.Bottom.CalcPosPoint(Round(X)));
- end;
- with (Chart4.Tools[0] as TRectangleTool) do
- //if Clicked(Round(X),Round(Y)) = True then
- begin
- DifX := Round(X-Shape.Left);
- DifY := Round(Y-Shape.Top);
- OrigXPos := Round(X); //Round(Chart1.Axes.Bottom.CalcPosPoint(Round(X)));
- end;
- FDragging := True;
- end;
- end.
Add Comment
Please, Sign In to add comment