GD::Graph: "mixed" graph doesn't recognize "area" graph type

E

Emilio Mayorga

Hi,

I'm using the GD::Graph module to create some graphs (great module,
BTW!). Everything works fine. But in a "mixed" graph, "area" graphs
are not recognized. I get this error message:
[snip] unknown type area, assuming lines at [snip]
I am trying to create a chart with two lines and three area graphs.
The lines work fine. Area graphs work fine when used by themselves
(not in a mixed graph); I wrote a small program to test this.

I am using ActiveState Perl 5.6.1 on Win2000; GD 1.27, GD::Graph 1.31.
I've read in the documentation that support for "mixed" is fairly
limited, but area is included in the sample "types" assignment in the
documenation.

The X-axis on my graph is numerical. I don't know if that makes a
difference.

Thanks!

-Emilio
 
M

Martien Verbruggen

Hi,

I'm using the GD::Graph module to create some graphs (great module,
BTW!). Everything works fine. But in a "mixed" graph, "area" graphs
are not recognized. I get this error message:
[snip] unknown type area, assuming lines at [snip]
I am trying to create a chart with two lines and three area graphs.
The lines work fine. Area graphs work fine when used by themselves
(not in a mixed graph); I wrote a small program to test this.

That's odd. Area charts should work. There's an example (sample61) in
the distribution that uses lines, bars, points, area, and linespoints,
all in one chart. Where is the code you tried?
I am using ActiveState Perl 5.6.1 on Win2000; GD 1.27, GD::Graph 1.31.

You should upgrade GD::Graph. That's a rather old version. But I don't
think that that is your problem. sample61 was already in the
distribution back then.
I've read in the documentation that support for "mixed" is fairly
limited, but area is included in the sample "types" assignment in the
documenation.

Indeed. And it should work.
The X-axis on my graph is numerical. I don't know if that makes a
difference.

It might, since bar charts and area charts are not normally used with
numerical X axes. I probably never tried them. However, I don't think
you should get that message anyway. I just tried sample61 with numerical
axes, in my development tree, and didn't get that message, but I'm a
few versions ahead of you.

You should probably just show the (minimal) code example that produces
this problem.

Martien
 
E

Emilio Mayorga

Martien Verbruggen said:
Hi,

I'm using the GD::Graph module to create some graphs (great module,
BTW!). Everything works fine. But in a "mixed" graph, "area" graphs
are not recognized. I get this error message:
[snip] unknown type area, assuming lines at [snip]
I am trying to create a chart with two lines and three area graphs.
The lines work fine. Area graphs work fine when used by themselves
(not in a mixed graph); I wrote a small program to test this.

That's odd. Area charts should work. There's an example (sample61) in
the distribution that uses lines, bars, points, area, and linespoints,
all in one chart. Where is the code you tried?

Thanks, Martin. BTW, I have your book; it's a great resource. I got
GD::Graph from the ActiveState site, and it didn't come with samples.
I went ahead and got sample61 from CPAN. It ran just fine with my
current versions of GD and GD::Graph!!

The code is somewhat complex. It connects to an Access database using
Win32::OLE and the DAO (the precursor to ADO), and pulls data in. Then
it goes off to create several graphs and png files from them, and HTML
files. I use the GD::Graph::Data class and the add_point method to add
data to the graphs. It's all a little messy and not so well documented
right now. If you really want to see it, you can grab it here (I've
removed strings that hold full file paths, to cover my back with my
employer):
http://www.co.snohomish.wa.us/publicwk/swm/maps/floodwarn2.pl
You'll find a sample output graph here:
http://www.co.snohomish.wa.us/publicwk/swm/maps/hydrograph_sens585.png
The three colored dashed horizontal lines are the ones I'm trying to
turn into area graphs. Each one of them is specified as a simple set
of two points, the start and end of the line.

As for the graph overall, basically, it's a time series with one
vertical reference line, and three horizontal reference lines that I'd
like to turn into area graphs.
You should upgrade GD::Graph. That's a rather old version. But I don't
think that that is your problem. sample61 was already in the
distribution back then.

Those are the versions that ActiveState had a year ago. Anyways, it
does like the version may not be the problem. Like I said, sample61
does work, and so does a test I ran using an area graph (not "mixed").
I also tried creating a legend, and that worked as it should: the area
graphs got area-type legends, even though the graph themselves gave
me the error message and were created with the default type (lines).
It might, since bar charts and area charts are not normally used with
numerical X axes. I probably never tried them. However, I don't think
you should get that message anyway. I just tried sample61 with numerical
axes, in my development tree, and didn't get that message, but I'm a
few versions ahead of you.

You should probably just show the (minimal) code example that produces
this problem.

I'm not sure where the problem is exactly, so I'm not sure what code
fragments to show you. I've tried removing some of the graph options,
but to no effect. Here are the lines that add the two points for each
of the three graphs that I want to plot as area graphs:
$data->add_point($tm{min}, undef, undef,
$sensorgraph{$sensor_id}->{floodphase1},
$sensorgraph{$sensor_id}->{floodphase2},
$sensorgraph{$sensor_id}->{floodphase3});
$data->add_point($tm{max}, undef, undef,
$sensorgraph{$sensor_id}->{floodphase1},
$sensorgraph{$sensor_id}->{floodphase2},
$sensorgraph{$sensor_id}->{floodphase3});

Points for the other two graphs (1st and 2nd graphs) are added in
separate statements. This is the code that sets all graph options:
$chart = GD::Graph::mixed->new(630,450); # 700,500

# set graph layout properties
$chart->set(
r_margin => 20,
t_margin => 10,
b_margin => 20,
transparent => 0,
fgclr => 'dgray',
labelclr => 'black',
axislabelclr => 'black',
line_width => 2,
x_long_ticks => 0,
x_tick_number => 36,
x_label_skip => 3,
x_min_value => $tm{min},
x_max_value => $tm{max},
x_number_format => \&x_format,
y_label => 'Stage (ft)',
y_long_ticks => 1,
y_min_value => $sensorgraph{$sensor_id}->{lowgraph},
y_max_value => $sensorgraph{$sensor_id}->{highgraph},
types => [qw(lines lines area area area)],
line_types => [1, 3, 2, 2, 2],
dclrs => [qw(blue gray green lyellow lred)]
);

Note that I've tried it without the "line_types" option, but it made
no difference.

Thanks for your help!

-Emilio
 
M

Martien Verbruggen

Martien Verbruggen said:
Hi,

I'm using the GD::Graph module to create some graphs (great module,
BTW!). Everything works fine. But in a "mixed" graph, "area" graphs
are not recognized. I get this error message:
[snip] unknown type area, assuming lines at [snip]
I am trying to create a chart with two lines and three area graphs.
The lines work fine. Area graphs work fine when used by themselves
(not in a mixed graph); I wrote a small program to test this.

That's odd. Area charts should work. There's an example (sample61) in
the distribution that uses lines, bars, points, area, and linespoints,
all in one chart. Where is the code you tried?
http://www.co.snohomish.wa.us/publicwk/swm/maps/floodwarn2.pl
You'll find a sample output graph here:
http://www.co.snohomish.wa.us/publicwk/swm/maps/hydrograph_sens585.png
The three colored dashed horizontal lines are the ones I'm trying to
turn into area graphs. Each one of them is specified as a simple set
of two points, the start and end of the line.

I've had a bit of a look at it, but I can't really see what's wrong with
it (if anything at all). Would it be possible for you to just fill the
$sensorgraph{$sensorid} hashes with some decent values, and then run the
GD::Graph part separately? if you then still see problems, please email
the result to me, because that probably means there is some bug or
oddity that I need to have a look at.

Thanks,
Martien
 
E

Emilio Mayorga

Martien Verbruggen said:
Martien Verbruggen said:
On 30 Sep 2003 11:55:49 -0700,
Hi,

I'm using the GD::Graph module to create some graphs (great module,
BTW!). Everything works fine. But in a "mixed" graph, "area" graphs
are not recognized. I get this error message:
[snip] unknown type area, assuming lines at [snip]
I am trying to create a chart with two lines and three area graphs.
The lines work fine. Area graphs work fine when used by themselves
(not in a mixed graph); I wrote a small program to test this.

That's odd. Area charts should work. There's an example (sample61) in
the distribution that uses lines, bars, points, area, and linespoints,
all in one chart. Where is the code you tried?
http://www.co.snohomish.wa.us/publicwk/swm/maps/floodwarn2.pl
You'll find a sample output graph here:
http://www.co.snohomish.wa.us/publicwk/swm/maps/hydrograph_sens585.png
The three colored dashed horizontal lines are the ones I'm trying to
turn into area graphs. Each one of them is specified as a simple set
of two points, the start and end of the line.

I've had a bit of a look at it, but I can't really see what's wrong with
it (if anything at all). Would it be possible for you to just fill the
$sensorgraph{$sensorid} hashes with some decent values, and then run the
GD::Graph part separately? if you then still see problems, please email
the result to me, because that probably means there is some bug or
oddity that I need to have a look at.

Thanks for looking into it. I'll try to do that test, but a deadline
is creeping up on me, so it may be a while. I'll definitely try to
follow up if the problem persists. I expect to make heavy use of
GD::Graph for several projects in the future.

Best,

Emilio
 
E

Emilio Mayorga

Thanks for looking into it. I'll try to do that test, but a deadline
is creeping up on me, so it may be a while. I'll definitely try to
follow up if the problem persists. I expect to make heavy use of
GD::Graph for several projects in the future.

I've found the problem. The error message comes up when there are
undef values in the area graph. I was able to reproduce it in
sample61.pl by just setting one of the area graph values to undef.

I suppose there is logic to why an area graph would not work when
there is an undef, but the error message is misleading.

I rearranged how my graphs are created so that the area graphs would
have no undef's. That eliminated the error messages, but it also
eliminated the graphs intended to be area graphs! They don't show up.
I haven't figured out what's going on.

On a more general note, it seems restrictive to have to associate all
graphs with exactly the same set of x-values, especially for a numeric
x-axis (continuous values). *BUT*, I really appreciate the work you've
done in putting together this module.

Thanks.

-Emilio
 
M

Martien Verbruggen

I've found the problem. The error message comes up when there are
undef values in the area graph. I was able to reproduce it in
sample61.pl by just setting one of the area graph values to undef.

Thanks for that. I'll look into that to see why I decided to make it
behave in that way.
I suppose there is logic to why an area graph would not work when
there is an undef, but the error message is misleading.

There is probably a reason, yes, but I agree that the error message
needs some work.
On a more general note, it seems restrictive to have to associate all
graphs with exactly the same set of x-values, especially for a numeric
x-axis (continuous values).

I agree. Fixing that is non-trivial however, and has been on my todo
list for quite a while. GD::Graph started its life intended for
something much simpler than what it has evolved into and bad design
decisions were made early on.

Martien
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,733
Messages
2,569,440
Members
44,832
Latest member
GlennSmall

Latest Threads

Top