CodeCharge Studio
search Register Login  

Web Reports

Visually create Web Reports in PHP, ASP, .NET, Java, Perl and ColdFusion.
CodeCharge.com

YesSoftware Forums -> CodeCharge Studio -> Perl

 Draw a bar graph with GD::Graph::bars

Print topic Send  topic

Author Message
Oren
Posted: 04/19/2005, 7:52 AM

Hi .. i was looking for a way to draw charts and bars with perl and came accross: http://www.wdvl.com/Authoring/Langu...e/chart1-1.html

i'm trying to use this example:
1 use strict;
2 use GD::Graph::bars;
3
4 my @data = (
5 ["Jan-01","Feb-01","Mar-01", "Apr-01","May-01",
"Jun-01","Jul-01","Aug-01","Sep-01"],
6 [21,25,33,39,49,48,40,45,15]
7 );
8
9 my $graph = new GD::Graph::bars;
10
11 $graph->set(
12 x_label => 'Month',
13 y_label => 'Revenue ($1,000s)',
14 title => 'Monthly Online Sales for 2001',
15 bar_spacing => 10
16 )
17 or warn $graph->error;
18
19 $graph->plot(\@data) or die $graph->error;
20
21 open(GRAPH,">graph1.jpg") || die "Cannot open graph1.jpg: $!\n";
22 print GRAPH $graph->gd->jpeg(100);

but it seems that the jpeg output is illigal or incoerect ... do you guys have any idea ?

Oren
dhempy


Posts: 40
Posted: 04/19/2005, 10:35 AM

Is this running as CGI? If so, you probably want to give a content-type. Something like this, as the first thing your script prints:

print "Content-type: image/jpeg\n\n";  ## Or do the same thing with CGI.pm

You'll also want to make sure your web server isn't providing its own text/html content type.

Alternately, you could have your script write the jpeg to a temp file on your server, and then have your cgi script create an <img> tag that links to that generated file. You'll need to deal with unique names and clean up and such, but that shouldn't be too bad.

HTH,
-dave

_________________
David Hempy
Director of Broadcast and Education Technology
Kentucky Educational Television
800-333-9764
View profile  Send private message
Oren
Posted: 04/19/2005, 10:12 PM

i'm running it as a simple script, which generates an jpeg output .....

but the jpeg comes out iligall ....
Last Hero
Posted: 04/19/2005, 11:49 PM

open(GRAPH,">graph1.jpg") || die "Cannot open graph1.jpg: $!\n";
binmode GRAPH;
print GRAPH $graph->gd->jpeg(100);
close GRAPH;
im cool
Posted: 05/07/2005, 10:43 PM

FREAKS
im cool
Posted: 05/07/2005, 10:48 PM

um i have a question ummmmm y arent the bars always coloured i mean hello what is this world cumin to the colours make it exciting just thought i needed to say this - is this like a freak club can i join is it like msn cause im so popular :-| 8-)
Pamela Snelling
Posted: 05/17/2005, 9:39 AM

O:):-@:-<:-P:-Oi hate you:-{};-):-|:-( off
Pamela Snelling
Posted: 05/17/2005, 9:39 AM

O:):-@:-<:-P:-Oi hate you:-{};-):-|:-( off
Pamela Snelling
Posted: 05/17/2005, 9:39 AM

O:):-@:-<:-P:-Oi hate you:-{};-):-|:-( off
rajesh
Posted: 06/04/2005, 3:52 AM

how to draw bar graphs simply with the available datas?
Last Hero
Posted: 06/05/2005, 6:44 AM

Quote :
how to draw bar graphs simply with the available datas?
RTFM, dude

perldoc GD
perldoc GD::Graph

Add new topic Subscribe to topic   


These are Community Forums for users to exchange information.
If you would like to obtain technical product help please visit http://support.yessoftware.com.

MS Access to Web

Convert MS Access to Web.
Join thousands of Web developers who build Web applications with minimal coding.

CodeCharge.com

Home   |    Search   |    Members   |    Register   |    Login


Powered by UltraApps Forum created with CodeCharge Studio
Copyright 2003-2004 by UltraApps.com  and YesSoftware, Inc.