[Lazarus] TAChart OHLC

2014-09-13 Thread Leonardo M. Ramé
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
Date,Open,High,Low,Close,Volume
10-Sep-14,98.01,101.11,97.76,101.00,100869587
9-Sep-14,99.08,103.08,96.14,97.99,189846255
8-Sep-14,99.30,99.31,98.05,98.36,46356742
5-Sep-14,98.80,99.39,98.31,98.97,58457035
4-Sep-14,98.85,100.09,97.79,98.12,85718221
3-Sep-14,103.10,103.20,98.58,98.94,125420521
2-Sep-14,103.06,103.74,102.72,103.30,53564262
29-Aug-14,102.86,102.90,102.20,102.50,44595247
28-Aug-14,102.13,102.78,101.56,102.25,68459801
27-Aug-14,101.02,102.57,100.70,102.13,52369011
26-Aug-14,101.42,101.50,100.86,100.89,33151984
25-Aug-14,101.79,102.17,101.28,101.54,40270173
22-Aug-14,100.29,101.47,100.19,101.32,44183834
21-Aug-14,100.57,100.94,100.11,100.58,33478198
20-Aug-14,100.44,101.09,99.95,100.57,52699192
19-Aug-14,99.41,100.68,99.32,100.53,69399270
18-Aug-14,98.49,99.37,97.98,99.16,47572413
15-Aug-14,97.90,98.19,96.86,97.98,48951331
14-Aug-14,97.33,97.57,96.80,97.50,28115566
13-Aug-14,96.15,97.24,96.04,97.24,31916439
12-Aug-14,96.04,96.88,95.61,95.97,33795352
11-Aug-14,95.27,96.08,94.84,95.99,36584844
8-Aug-14,94.26,94.82,93.28,94.74,41865193
7-Aug-14,94.93,95.95,94.10,94.48,46711179
6-Aug-14,94.75,95.48,94.71,94.96,38558342
5-Aug-14,95.36,95.68,94.36,95.12,55932663
4-Aug-14,96.37,96.58,95.17,95.59,39958144
1-Aug-14,94.90,96.62,94.81,96.13,48511286
31-Jul-14,97.16,97.45,95.33,95.60,56842647
30-Jul-14,98.44,98.70,97.67,98.15,33010001
29-Jul-14,99.33,99.44,98.25,98.38,43143095
28-Jul-14,97.82,99.24,97.55,99.02,55317689
25-Jul-14,96.85,97.84,96.64,97.67,43469117
24-Jul-14,97.04,97.32,96.42,97.03,45728843
23-Jul-14,95.42,97.88,95.17,97.19,92917719
22-Jul-14,94.68,94.89,94.12,94.72,55196597
21-Jul-14,94.99,95.00,93.72,93.94,39079002
18-Jul-14,93.62,94.74,93.02,94.43,49987593
17-Jul-14,95.03,95.28,92.57,93.09,57298243
16-Jul-14,96.97,97.10,94.74,94.78,53502415
15-Jul-14,96.80,96.85,95.03,95.32,45696176
14-Jul-14,95.86,96.89,95.65,96.45,42810155

[Lazarus] TAChart OHLC

2014-09-13 Thread Werner Pamler
You need to initialize the YCount of the chart source. Just call 
Chart1OpenHighLowCloseSeries1.ListSource.YCount := 4 before adding the 
data. 
(http://wiki.lazarus.freepascal.org/TAChart_documentation#Open-high-low-close_series)



--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus