Recent

Author Topic: [SOLVED] TChart nogui demo bug  (Read 1307 times)

cpicanco

  • Hero Member
  • *****
  • Posts: 618
  • Behavioral Scientist and Programmer
    • Portfolio
[SOLVED] TChart nogui demo bug
« on: September 23, 2017, 04:47:27 am »
I am getting a "font file not found" error when running the nogui example of TAChart. I copied the folder:

/usr/share/lazarus/1.8.0RC4/components/tachart/demo/nogui/

to

/home/some/place

I have tried "Arial", "default" and "Monospace".

Also changed  TADrawerFPCanvas in '../../TADrawerFPCanvas.pas' to TADrawerFPCanvas



« Last Edit: September 25, 2017, 02:43:12 pm by cpicanco »
Be mindful and excellent with each other.
https://github.com/cpicanco/

cpicanco

  • Hero Member
  • *****
  • Posts: 618
  • Behavioral Scientist and Programmer
    • Portfolio
Re: TChart nogui demo bug
« Reply #1 on: September 23, 2017, 06:44:23 am »
Solved:
 :D
Code: Pascal  [Select][+][-]
  1. #!/usr/bin/env instantfpc
  2. {$mode objfpc}{$H+}
  3. uses
  4.   Interfaces, Classes, TAChartLazarusPkg,
  5.   FPCanvas, FPImage, FPImgCanv,
  6.   TAGraph,
  7.   TASeries,
  8.   TADrawerFPCanvas in './tadrawerfpcanvas.pas',
  9.   TADrawerCanvas,
  10.   TADrawUtils,
  11.   math,
  12.   TSVDocument;
  13.  
  14. const
  15.   filename = '/home/rafael/recordings/2016_10_26/000/stimulus_control/000.timestamps';
  16.  
  17. var
  18.   Document : TTSVDocument;
  19.   StringList : TStringList;
  20.   Chart : TChart;
  21.   LineSerie : TLineSeries;
  22.  
  23.   CanvasImage: TFPMemoryImage;
  24.   Canvas: TFPImageCanvas;
  25.   DrawerInterface: IChartDrawer;
  26.  
  27.   data : array of Double;
  28.   i : integer;
  29.   error:  integer = 0;
  30.  
  31. begin
  32.   Chart := TChart.Create(nil);
  33.   Chart.Font.Name:='/usr/share/fonts/truetype/freefont/FreeMono';
  34.   Chart.LeftAxis.Marks.LabelFont.Name := '/usr/share/fonts/truetype/freefont/FreeMono';
  35.   Chart.LeftAxis.Marks.LabelFont.Size := 12;
  36.   Chart.LeftAxis.Marks.LabelFont.Orientation := 0;
  37.   Chart.LeftAxis.Marks.Visible:=True;
  38.   Chart.LeftAxis.Grid.Style:=psClear;
  39.  
  40.   Chart.LeftAxis.Title.Visible:=True;
  41.   Chart.LeftAxis.Title.Caption := 'Respostas';
  42.   Chart.LeftAxis.Title.LabelFont.Name := '/usr/share/fonts/truetype/freefont/FreeMono';
  43.   Chart.LeftAxis.Title.LabelFont.Size := 12;
  44.   Chart.LeftAxis.Title.LabelFont.Orientation := 900;
  45.  
  46.   Chart.BottomAxis.Marks.Visible := false;
  47.   Chart.BottomAxis.Grid.Style := psClear;
  48.   Chart.BottomAxis.Title.Caption := 'Tempo';
  49.   Chart.BottomAxis.Title.Font.Name := '/usr/share/fonts/truetype/freefont/FreeMono';
  50.   Chart.BottomAxis.Title.Visible:=True;
  51.  
  52.  
  53.   Chart.Color := $FFFFFF;
  54.   Chart.BackColor := $FFFFFF;
  55.  
  56.   Chart.Title.Visible := True;
  57.   Chart.Title.Text.Text := 'test';
  58.   Chart.Title.Font.Name := '/usr/share/fonts/truetype/freefont/FreeMono';
  59.   Chart.Title.Font.Size := 12;
  60.   Chart.Title.Font.Orientation := 0;
  61.   Chart.Width := 800;
  62.   Chart.Height:= 800;
  63.  
  64.   Document := TTSVDocument.Create;
  65.   Document.LoadFromFile(Filename);
  66.   Document.SkipHeader := 5;
  67.  
  68.   StringList := Document.Filter('Event', 'R', 'Time');
  69.   try
  70.     SetLength(data, StringList.Count);
  71.     for i := 0 to StringList.Count -1 do
  72.       Val(StringList[i], data[i], error);
  73.  
  74.  
  75.     LineSerie := TLineSeries.Create(Chart);
  76.     LineSerie.AddArray(data);
  77.     Chart.AddSeries(LineSerie);
  78.  
  79.     CanvasImage := TFPMemoryImage.Create(Chart.Width, Chart.Height);
  80.     Canvas := TFPImageCanvas.Create(CanvasImage);
  81.     DrawerInterface := TFPCanvasDrawer.Create(Canvas);
  82.     DrawerInterface.DoGetFontOrientation := @CanvasGetFontOrientationFunc;
  83.     Chart.Draw(DrawerInterface, Rect(0, 0, Chart.Width, Chart.Height));
  84.     CanvasImage.SaveToFile('test.png');
  85.   finally
  86.     Canvas.Free;
  87.     CanvasImage.Free;
  88.     StringList.Free;
  89.     Document.Free;
  90.     Chart.Free;
  91.   end;
  92. end.
  93.  
Be mindful and excellent with each other.
https://github.com/cpicanco/

 

TinyPortal © 2005-2018