The Author Online Book Forums are Moving

The Author Online Book Forums will soon redirect to Manning's liveBook and liveVideo. All book forum content will migrate to liveBook's discussion forum and all video forum content will migrate to liveVideo. Log in to liveBook or liveVideo with your Manning credentials to join the discussion!

Thank you for your engagement in the AoF over the years! We look forward to offering you a more enhanced forum experience.

import-bot (20211) [Avatar] Offline
#1
[Originally posted by jimferree]

I have the following data I am trying to load

#Data generated by summarize_ftr_data_for_plotting.pl script on my h:drive
20010501 6
20010601 3
20010701 2
20010801 1
20010901 1
20011001 1
20011101 2
20011201 0
20020101 0
20020201 2
20020301 1
20020401 2
20020501 0
20020601 1
20020701 2
20020801 2


I have the following code:

#use GD::Graph::area;
use GD::Graph:smilieata;
use GD::Graph::linespoints;
use Text:smiliearseWords;
my $data = GD::Graph:smilieata->new();

open(IN, "$output_summary_file") or die "Can't read $output_summary_file: $!";
while(<IN>smilie
{
next if (/^#/ || /^s/);
chomp($_);
#my @d = map {$_ eq '' ? undef : $_} split / /;
#$data->add_point(@d);
#print "$d[0],$d[1]
";
my @d = quotewords(' ', 0, $_);
$data->add_point($d[0], $d[1]);
}
close(IN);


my $chart = new GD::Graph::linespoints(700,500);
$chart->set(
x_label => 'Month',
y_label => '# sold',
title => 'First three quarters, 2000',
y_long_ticks => 1,
markers => [1, 5],
marker_size => 8,
);
$chart->set_legend('outlet 1');

$chart->set_title_font('arialbd', 24);
$chart->set_x_axis_font('arial', 16);
$chart->set_y_axis_font('arial', 16);
$chart->set_x_label_font('arial', 1smilie;
$chart->set_y_label_font('arial', 1smilie;
$chart->set_legend_font('arial', 14);
$chart->plot(@data) or die $chart->error();
my $gd = $chart->gd;
open(IMG, ">$output_summary_file_linespoints"smilie or die $!;
binmode IMG;
print IMG $gd->png;
close IMG;


Get error message for line "$chart->plot(@data) or die $chart->error();"
No data sets or points at summarize_ftr_data_for_plotting.pl line XXX

The data is tab seperated. I have run out of things to try.
Thanks for any help
import-bot (20211) [Avatar] Offline
#2
Re: Problem loading data
[Originally posted by jimferree]

I noticed that when I pasted in the code I lost the in
$chart->plot(@data)

should be

$chart->plot(@data)

It was in my original code but not the code I copied to the web
import-bot (20211) [Avatar] Offline
#3
Re: Problem loading data
[Originally posted by mgjv]

> I have the following data I am trying to load
>
> #Data generated by summarize_ftr_data_for_plotting.pl script on my h:drive
> 20010501 6
> 20010601 3
> 20010701 2
> 20010801 1
> 20010901 1
> 20011001 1
> 20011101 2
> 20011201 0
> 20020101 0
> 20020201 2
> 20020301 1
> 20020401 2
> 20020501 0
> 20020601 1
> 20020701 2
> 20020801 2
>
>
> I have the following code:
>
> #use GD::Graph::area;
> use GD::Graph:smilieata;
> use GD::Graph::linespoints;
> use Text:smiliearseWords;
> my $data = GD::Graph:smilieata->new();
>
> open(IN, "$output_summary_file"smilie or die "Can't read $output_summary_file:
$!";
> while(<IN>smilie
> {
> next if (/^#/ || /^s/);
> chomp($_);
> #my @d = map {$_ eq '' ? undef : $_} split / /;
> #$data->add_point(@d);
> #print "$d[0],$d[1]

I presume you did actually try this code as well, even though it is commented
out now?

> ";
> my @d = quotewords(' ', 0, $_);
> $data->add_point($d[0], $d[1]);
> }
> close(IN);
>
>
> my $chart = new GD::Graph::linespoints(700,500);
> $chart->set(
> x_label => 'Month',
> y_label => '# sold',
> title => 'First three quarters, 2000',
> y_long_ticks => 1,
> markers => [1, 5],
> marker_size => 8,
> );
> $chart->set_legend('outlet 1');
>
> $chart->set_title_font('arialbd', 24);
> $chart->set_x_axis_font('arial', 16);
> $chart->set_y_axis_font('arial', 16);
> $chart->set_x_label_font('arial', 1smilie;
> $chart->set_y_label_font('arial', 1smilie;
> $chart->set_legend_font('arial', 14);
> $chart->plot(@data) or die $chart->error();

There's a missing backslash in here, but I think in your followup you're
trying to tell me that that was there in the original code.

> my $gd = $chart->gd;
> open(IMG, ">$output_summary_file_linespoints"smilie or die $!;
> binmode IMG;
> print IMG $gd->png;
> close IMG;
>
>
> Get error message for line "$chart->plot(@data) or die $chart->error();"
> No data sets or points at summarize_ftr_data_for_plotting.pl line XXX
>
> The data is tab seperated. I have run out of things to try.
> Thanks for any help

I can't really see anything wrong with this code. It should work, as far as I
can tell. One thing you could try is isolate the code bits that parse the
input file, and just put some print statements in there to see what it parses.
Then you could use the GD::Graph:smilieata get_x() and get_y() methods to
investigate what is actually in the data set.

If all of that doesn't help, feel free to email me the complete program and
data file, and I'll see whether I can find out what is going on.

Martien