[Lazarus] TAChart OHLC

"Leonardo M. Ramé" l.rame at griensu.com
Sun Sep 14 00:18:10 CEST 2014


Hi, I'm trying to create a basic Open High Low Close chart using 
TAChart, but I'm getting a RunError(201) on "tacustomsource.pas" line 
433, aparently YList is not initialized.

Here's the lfm:

object Form1: TForm1
   Left = 364
   Height = 354
   Top = 255
   Width = 582
   Caption = 'Form1'
   ClientHeight = 354
   ClientWidth = 582
   OnShow = FormShow
   LCLVersion = '1.3'
   object Chart1: TChart
     Left = 0
     Height = 354
     Top = 0
     Width = 582
     AxisList = <
       item
         Minors = <>
         Title.LabelFont.Orientation = 900
       end
       item
         Alignment = calBottom
         Minors = <>
       end>
     Foot.Brush.Color = clBtnFace
     Foot.Font.Color = clBlue
     Title.Brush.Color = clBtnFace
     Title.Font.Color = clBlue
     Title.Text.Strings = (
       'TAChart'
     )
     Align = alClient
     ParentColor = False
     object Chart1OpenHighLowCloseSeries1: TOpenHighLowCloseSeries
     end
   end
end

And Here's the .pas

unit Unit1;

{$mode objfpc}{$H+}

interface

uses
   Classes, SysUtils, FileUtil, TAGraph, TASources, TAIntervalSources,
   TAMultiSeries, Forms, Controls, Graphics, Dialogs,
   StrUtils, DateUtils, TACustomSeries;

type

   { TForm1 }

   TForm1 = class(TForm)
     Chart1: TChart;
     Chart1OpenHighLowCloseSeries1: TOpenHighLowCloseSeries;
     procedure FormShow(Sender: TObject);
   private
     { private declarations }
   public
     { public declarations }
   end;

var
   Form1: TForm1;

implementation

{$R *.lfm}

{ TForm1 }


procedure TForm1.FormShow(Sender: TObject);
var
   lCSV: TStringList;
   lLine: TStringList;
   I: Integer;
   lDate: TDate;
   lOpen: double;
   lHigh: double;
   lLow: double;
   lClose: double;
   lStr: string;
begin
   lCSV := TStringList.Create;
   lLine := TStringList.Create;
   DefaultFormatSettings.DateSeparator:='-';
   DefaultFormatSettings.ShortDateFormat:='D-MMM-Y';
   DefaultFormatSettings.ShortMonthNames[1] := 'Jan';
   DefaultFormatSettings.ShortMonthNames[2] := 'Feb';
   DefaultFormatSettings.ShortMonthNames[3] := 'Mar';
   DefaultFormatSettings.ShortMonthNames[4] := 'Apr';
   DefaultFormatSettings.ShortMonthNames[5] := 'May';
   DefaultFormatSettings.ShortMonthNames[6] := 'Jun';
   DefaultFormatSettings.ShortMonthNames[7] := 'Jul';
   DefaultFormatSettings.ShortMonthNames[8] := 'Aug';
   DefaultFormatSettings.ShortMonthNames[9] := 'Sep';
   DefaultFormatSettings.ShortMonthNames[10] := 'Oct';
   DefaultFormatSettings.ShortMonthNames[11] := 'Nov';
   DefaultFormatSettings.ShortMonthNames[12] := 'Dec';
   try
     lCSV.LoadFromFile('aapl.csv');
     for I := 0 to lCSV.Count - 1 do
     begin
       if I = 0 then
         continue;
       lLine.CommaText:= lCSV[I];
       lDate := ScanDateTime('d-mmm-y', lLine[0]);
       lOpen := StrToFloat(lLine[1]);
       lHigh := StrToFloat(lLine[2]);
       lLow := StrToFloat(lLine[3]);
       lClose := StrToFloat(lLine[4]);
       Chart1OpenHighLowCloseSeries1.AddXOHLC(I, lOpen, lHigh, lLow, 
lClose, DateToStr(lDate));
     end;
   finally
     lLine.Free;
     lCSV.Free;
   end;
end;

end.

Also I attached the file "aapl.csv" I'm using to feed the data.

-- 
Leonardo M. Ramé
http://leonardorame.blogspot.com
-------------- next part --------------
A non-text attachment was scrubbed...
Name: aapl.csv
Type: text/csv
Size: 10832 bytes
Desc: not available
URL: <http://lists.lazarus-ide.org/pipermail/lazarus/attachments/20140913/7f1fc208/attachment.csv>


More information about the Lazarus mailing list