ASE Home Page Products Download Purchase Support About ASE
ChartDirector Support
Forum HomeForum Home   SearchSearch

Message ListMessage List     Post MessagePost Message

  Perl String Arrays
Posted by Gary on Oct-03-2021 01:57
Attachments:
I have current version of ChartDirector functioning in a  Windows10 environment   I can run the candlestick.pl sample and it works fine.  When I create a version to pull in the data from a file I am not getting a correct chart.  I've tried a number of ways to create the arrays (starting with loading a normal Perl array) but settled on looping through the record and building a string as below.

if($labels eq "")
{
$labels = """ . $Values[0] . """;
$highData = $Values[1];
$lowData = $Values[2];
$openData = $Values[3];
$closeData = $Values[4];
}
else
{
$labels = $labels . ", " . """ . $Values[0] . """;
$highData = $highData . ', ' . $Values[1];
$lowData= $lowData . ', ' . $Values[2];
$openData = $openData . ', ' . $Values[3];
$closeData = $closeData . ', ' . $Values[4];
}

That gives me strings that look like the following:

labels
"20210902", "20210903", "20210907", "20210908", "20210909", "20210910", "20210913", "20210914", "20210915", "20210916", "20210917", "20210920", "20210921", "20210922", "20210923", "20210924", "20210927", "20210928", "20210929", "20210930", "20211001"

high data
154.72, 154.63, 157.26, 157.04, 156.11, 155.48, 151.42, 151.07, 149.44, 148.97, 148.82, 144.84, 144.6, 146.43, 147.08, 147.47, 145.96, 144.75, 144.45, 144.378, 142.92

Then I reassign those strings to an array as follows:

$labels = [$labels];
$highData = [$highData];
$lowData= [$lowData];
$openData = [$openData];
$closeData = [$closeData];

That got me past the "Error converting argument 1 to type class DoubleArray and similar error on the labels.  But it doesn't result  in a valid chart.  It doesn't appear that it recognizes the individual elements of the array.

I'm not sure what formatting is required here.  Any help would be appreciated.
gary_candlestick.png

  Re: Perl String Arrays
Posted by Gary on Oct-03-2021 10:43
Okay, I figured it out.  I was making it more difficult than it needs to be.

My Solution:

1. Build normal arrays (strings are quoted).

push(@labels,""" . $Values[0] . """);
push(@highData,$Values[1]);
push(@lowData,$lowData[2]);
push(@openData,$Values[3]);
push(@closeData,$Values[4]);

2. Create an array reference for each.

        my $ref_labels = [@labels];
        my $ref_highData = [@highData];
        my $ref_lowData = [@lowData];
        my $ref_openData = [@openData];
        my $ref_closeData = [@closeData];

3.  Pass the array reference for labels to the setLabels.

       $c->xAxis()->setLabels($ref_labels)->setFontAngle(45);

4.  Pass the high, low, open, close array references to the addCandleStickLayer function.

     my $layer = $c->addCandleStickLayer($ref_highData, $ref_lowData, $ref_openData, $ref_closeData, 0x00ff00, 0xff0000);