Forum > TAChart

Tchart with log scale and needed real time on X-axis

(1/10) > >>

Johan Holstein:
Dear all,

In my log graph I need on the X-axis real time in hh:mm:ss can someone help with my example....

Thanks in advance!
Best,

Johan



--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---unit Unit1; {$mode objfpc}{$H+} interface uses  Classes, SysUtils, FileUtil, TAGraph, TASeries, TATransformations, TASources,  TAChartExtentLink, TAChartCombos, TANavigation, TATools, Forms, Controls,  Graphics, Dialogs, ExtCtrls, Menus, ComCtrls, StdCtrls, Types; type   { TForm1 }   TForm1 = class(TForm)    Chart1: TChart;    ChartExtentLink1: TChartExtentLink;    ChartToolset1: TChartToolset;    ChartToolset1ZoomDragTool1: TZoomDragTool;    ChartToolset1ZoomDragTool2: TZoomDragTool;    ChartToolset1ZoomMouseWheelTool1: TZoomMouseWheelTool;    LineSeries: TLineSeries;    MainMenu1: TMainMenu;    MenuItem1: TMenuItem;    MenuItem10: TMenuItem;    MenuItem11: TMenuItem;    MenuItem12: TMenuItem;    MenuItem14: TMenuItem;    MenuItem15: TMenuItem;    MenuItem16: TMenuItem;    MenuItem2: TMenuItem;    MenuItem3: TMenuItem;    MenuItem4: TMenuItem;    MenuItem5: TMenuItem;    MenuItem6: TMenuItem;    MenuItem7: TMenuItem;    MenuItem8: TMenuItem;    MenuItem9: TMenuItem;    YAxisLabels: TListChartSource;    XAxisLabels: TListChartSource;    YAxisTransformation: TChartAxisTransformations;    YAxisLogTransform: TLogarithmAxisTransform;    XAxisTransformation: TChartAxisTransformations;    XAxisLogTransform: TLogarithmAxisTransform;    procedure ChartToolset1ZoomDragTool1AfterKeyDown(ATool: TChartTool;      APoint: TPoint);    procedure FormCreate(Sender: TObject);    procedure MenuItem10Click(Sender: TObject);    procedure MenuItem11Click(Sender: TObject);    procedure MenuItem12Click(Sender: TObject);    procedure MenuItem14Click(Sender: TObject);    procedure MenuItem15Click(Sender: TObject);    procedure MenuItem16Click(Sender: TObject);    procedure MenuItem3Click(Sender: TObject);    procedure MenuItem6Click(Sender: TObject);    procedure MenuItem7Click(Sender: TObject);    procedure MenuItem8Click(Sender: TObject);    procedure MenuItem9Click(Sender: TObject);   private    procedure CreateData;    procedure CreateAxisLabels(ASource: TListChartSource; AMin, AMax: Double);    procedure CreateAxisLabelsTime(ASource: TListChartSource; AMin, AMax: Double);  public   end; var  Form1: TForm1; implementation {$R *.lfm} uses  Math, TAChartUtils; { TForm1 } procedure TForm1.CreateData;  begin    //Add test data     //LineSeries.AddXY(1, 1e3);    //LineSeries.AddXY(5, 1e2);    //LineSeries.AddXY(10,1e1);    //LineSeries.AddXY(15,1e0);    //LineSeries.AddXY(20, 1e-1);    //LineSeries.AddXY(25, 1e-2);    //LineSeries.AddXY(30, 1e-3);    LineSeries.AddXY(35,1e-4);      LineSeries.ListSource.Sorted := true;end;  procedure TForm1.CreateAxisLabels(ASource: TListChartSource; AMin, AMax: Double);var  x: Double;begin  ASource.Clear;   x := power(10.0, floor(log10(AMin)));  while x <= AMax * 10 do begin            writeln(AMin);    ASource.Add(x, x, Format('10^%.0f', [Log10(x)]));     x := x * 10;       writeln(x);  end;end;  procedure TForm1.CreateAxisLabelsTime(ASource: TListChartSource; AMin, AMax: Double);var  x: Double;begin  ASource.Clear;   x := 0;  while x <= AMax * 10 do begin     ASource.Add(x, x, Format('10^%.0f', [Log10(x)]));     x := x +10 ;  end;end; procedure TForm1.FormCreate(Sender: TObject);     // default graph rangevar  ex: TDoubleRect;begin   CreateData;    // Calculate x axis labels for the x extent  CreateAxisLabels(XAxisLabels, ex.a.x, ex.b.x);    // Calculate y axis labels for the y extent        ex.b.y := 1e3;       ex.a.y := 1e-9;        Chart1.AxisList.Axes[0].Range.UseMax := True;       Chart1.AxisList.Axes[0].Range.UseMin := True;       Chart1.AxisList.Axes[0].Range.Min := 1e-9;       Chart1.AxisList.Axes[0].Range.Max := 1e3;        CreateAxisLabels(YAxisLabels, ex.a.y, ex.b.y);         Chart1.LeftAxis.Marks.Source := YAxislabels;       Chart1.LeftAxis.Marks.Style := smsLabel;        // Optional: Let axes start at first and end at last label      //Chart1.BottomAxis.Range.Max := XAxisLabels.Item[XAxisLabels.Count-1]^.X;      //Chart1.BottomAxis.Range.UseMax := true;      //Chart1.BottomAxis.Range.Min := XAxisLabels.Item[0]^.X;      //Chart1.BottomAxis.Range.UseMin := true;        Chart1.LeftAxis.Range.Max := 1e3  ;      Chart1.LeftAxis.Range.UseMax := true;      Chart1.LeftAxis.Range.Min := 1e-9 ;      Chart1.LeftAxis.Range.UseMin := true;       //Chart1.        LineSeries[1].AddXY(2, 2, FormatDateTime('dd/mm/yyyy', strtodate('01/01/2010')),1);  end;     procedure TForm1.MenuItem16Click(Sender: TObject);varex: TDoubleRect;begin      ex.b.y := 1e3;      ex.a.y := 1e-0;      CreateAxisLabels(YAxisLabels, ex.a.y, ex.b.y);      Chart1.LeftAxis.Marks.Source := YAxislabels;      Chart1.LeftAxis.Marks.Style := smsLabel;      Chart1.LeftAxis.Range.Max := 1e3  ;      Chart1.LeftAxis.Range.UseMax := true;      Chart1.LeftAxis.Range.Min := 1e-0 ;      Chart1.LeftAxis.Range.UseMin := true;  end; procedure TForm1.ChartToolset1ZoomDragTool1AfterKeyDown(ATool: TChartTool;  APoint: TPoint);begin end; procedure TForm1.MenuItem3Click(Sender: TObject);begin end;procedure TForm1.MenuItem15Click(Sender: TObject);varex: TDoubleRect;begin      ex.b.y := 1e3;      ex.a.y := 1e-1;      CreateAxisLabels(YAxisLabels, ex.a.y, ex.b.y);      Chart1.LeftAxis.Marks.Source := YAxislabels;      Chart1.LeftAxis.Marks.Style := smsLabel;      Chart1.LeftAxis.Range.Max := 1e3  ;      Chart1.LeftAxis.Range.UseMax := true;      Chart1.LeftAxis.Range.Min := 1e-1 ;      Chart1.LeftAxis.Range.UseMin := true; end;procedure TForm1.MenuItem14Click(Sender: TObject);varex: TDoubleRect;begin      ex.b.y := 1e3;      ex.a.y := 1e-2;      CreateAxisLabels(YAxisLabels, ex.a.y, ex.b.y);      Chart1.LeftAxis.Marks.Source := YAxislabels;      Chart1.LeftAxis.Marks.Style := smsLabel;      Chart1.LeftAxis.Range.Max := 1e3  ;      Chart1.LeftAxis.Range.UseMax := true;      Chart1.LeftAxis.Range.Min := 1e-2 ;      Chart1.LeftAxis.Range.UseMin := true; end;   procedure TForm1.MenuItem6Click(Sender: TObject);varex: TDoubleRect;begin      ex.b.y := 1e3;      ex.a.y := 1e-3;      CreateAxisLabels(YAxisLabels, ex.a.y, ex.b.y);      Chart1.LeftAxis.Marks.Source := YAxislabels;      Chart1.LeftAxis.Marks.Style := smsLabel;      Chart1.LeftAxis.Range.Max := 1e3  ;      Chart1.LeftAxis.Range.UseMax := true;      Chart1.LeftAxis.Range.Min := 1e-3 ;      Chart1.LeftAxis.Range.UseMin := true; end; procedure TForm1.MenuItem7Click(Sender: TObject);varex: TDoubleRect;begin     ex.b.y := 1e3;     ex.a.y := 1e-4;     CreateAxisLabels(YAxisLabels, ex.a.y, ex.b.y);     Chart1.LeftAxis.Marks.Source := YAxislabels;     Chart1.LeftAxis.Marks.Style := smsLabel;     Chart1.LeftAxis.Range.Max := 1e3  ;     Chart1.LeftAxis.Range.UseMax := true;     Chart1.LeftAxis.Range.Min := 1e-4 ;     Chart1.LeftAxis.Range.UseMin := true; end; procedure TForm1.MenuItem8Click(Sender: TObject);varex: TDoubleRect;begin     ex.b.y := 1e3;     ex.a.y := 1e-5;     CreateAxisLabels(YAxisLabels, ex.a.y, ex.b.y);     Chart1.LeftAxis.Marks.Source := YAxislabels;     Chart1.LeftAxis.Marks.Style := smsLabel;     Chart1.LeftAxis.Range.Max := 1e3  ;     Chart1.LeftAxis.Range.UseMax := true;     Chart1.LeftAxis.Range.Min := 1e-5 ;     Chart1.LeftAxis.Range.UseMin := true;end; procedure TForm1.MenuItem9Click(Sender: TObject);varex: TDoubleRect;begin    ex.b.y := 1e3;    ex.a.y := 1e-6;    CreateAxisLabels(YAxisLabels, ex.a.y, ex.b.y);    Chart1.LeftAxis.Marks.Source := YAxislabels;    Chart1.LeftAxis.Marks.Style := smsLabel;    Chart1.LeftAxis.Range.Max := 1e3  ;    Chart1.LeftAxis.Range.UseMax := true;    Chart1.LeftAxis.Range.Min := 1e-6 ;    Chart1.LeftAxis.Range.UseMin := true;end;procedure TForm1.MenuItem10Click(Sender: TObject);varex: TDoubleRect;begin      ex.b.y := 1e3;      ex.a.y := 1e-7;      CreateAxisLabels(YAxisLabels, ex.a.y, ex.b.y);      Chart1.LeftAxis.Marks.Source := YAxislabels;      Chart1.LeftAxis.Marks.Style := smsLabel;      Chart1.LeftAxis.Range.Max := 1e3  ;      Chart1.LeftAxis.Range.UseMax := true;      Chart1.LeftAxis.Range.Min := 1e-7 ;      Chart1.LeftAxis.Range.UseMin := true; end; procedure TForm1.MenuItem11Click(Sender: TObject);varex: TDoubleRect;begin      ex.b.y := 1e3;      ex.a.y := 1e-8;      CreateAxisLabels(YAxisLabels, ex.a.y, ex.b.y);      Chart1.LeftAxis.Marks.Source := YAxislabels;      Chart1.LeftAxis.Marks.Style := smsLabel;      Chart1.LeftAxis.Range.Max := 1e3  ;      Chart1.LeftAxis.Range.UseMax := true;      Chart1.LeftAxis.Range.Min := 1e-8 ;      Chart1.LeftAxis.Range.UseMin := true; end; procedure TForm1.MenuItem12Click(Sender: TObject);varex: TDoubleRect;begin      ex.b.y := 1e3;      ex.a.y := 1e-9;      CreateAxisLabels(YAxisLabels, ex.a.y, ex.b.y);      Chart1.LeftAxis.Marks.Source := YAxislabels;      Chart1.LeftAxis.Marks.Style := smsLabel;      Chart1.LeftAxis.Range.Max := 1e3  ;      Chart1.LeftAxis.Range.UseMax := true;      Chart1.LeftAxis.Range.Min := 1e-9 ;      Chart1.LeftAxis.Range.UseMin := true;end;   end. 

wp:
Log on the y axis, I assume, but also on the x axis? This does not make much sense for hh:nn:ss when this should be understood as the time diplayed on a clock. Or do you mean a time difference, for example the elapsed time after start of an experiment?

And what do you understand as "real-time"? A live display of data coming in? Should this be a scrolling window, or should always the full curve be displayed?

Johan Holstein:
The Y axis get data from my serial port (not implemented yet, and the graph must be a scrolling window with actual time. So a real time graph so that I can monitor my vacuum gauges in time.

Johan Holstein:
Something like this see picture,

Thaddy:
So what you really mean is the time on X and the Log scaled values on Y....
I thought the education at the RUG was much better than you question suggests. Should I doubt you or your lecturers...
Be more precise and the answers will be easier to formulate.
And quite simple.
Right now you are somewhat confusing both wp and me  ;D

Navigation

[0] Message Index

[#] Next page

Go to full version