|
perl array data plot |
Posted by Parm R. on Feb-13-2014 10:49 |
|
Hi,
i took the example from softlightbar.pl and want to populate the graph, with data read from a file. i get the data in the arrays using the code below. Now how do i pass it to chartdirector to plot the histograms.
for ($start=1;$start <= $#srr_data;$start++)
{
@mycurrent_line = split(";",$srr_data[$start]);
$data[$start] = "$mycurrent_line[2]";
$labels[$start] = "$mycurrent_line[1]";
}
Do i have to use the code below in "for loop" ?
$c->addBarLayer3($data[$start])->setBorderColor($perlchartdir::Transparent,perlchartdir::softLighting($perlchartdir::Left));
# Set x axis labels using the given labels
$c->xAxis()->setLabels($label[$start]); |
Re: perl array data plot |
Posted by Peter Kwan on Feb-13-2014 19:14 |
|
Hi Parm R.,
Assuming your for loop is correct, you just need to pass the array references of the data
and label arrays to ChartDirector.
$c->addBarLayer3(\\@data);
$c->xAxis()->setLabels(\\@labels);
You need to use \\@ because your code is using the @data array, while the original sample
code is using the $data array reference. In Perl, the \\ operator is use to get the reference
of an array.
If the above still does not work, please double check to see if your for loop is correct by
printing the @data and @labels array out. (I notice your code discards the first line of your
input and discards the first field of the @mycurrent_line. Without seeing your data format, I
am unable to determine if this is intentional or not.)
Hope this can help.
Regards
Peter Kwan |
Re: perl array data plot |
Posted by Parm R. on Feb-13-2014 21:13 |
|
Thanks Peter. It works. The first array elements were not used intentionally. |
|