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:
ata 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