in reply to Help with GD::Graph

Maybe you are looking for the X_labels_vertical option?
#!/usr/bin/perl use strict; use warnings; use GD::Graph::lines; my $data_ref = [ ['2004-01-08','2004-01-09','2004-01-10'], # X-values [ 15.9, 10.7, 15.8 ], # Y-value 1 [ 18,18,18 ], #Y-value 2 reference line [ 12,12,12 ], ]; my $graph = GD::Graph::lines->new(400, 300); $graph->set( transparent => '0', bgclr => 'lgray', boxclr => 'white', fgclr => 'white', x_label => 'Time', x_labels_vertical => 1, x_label_skip => 50, y_label => 'Price', title => 'Some simple graph', y_max_value => 20, y_tick_number => 1, y_label_skip => 2, long_ticks => 0, # make a grid of all the ticks ) or die $graph->error; my $gd_image = $graph->plot($data_ref) or die $graph->error; open(OUTPUT, ">$0.png") or die "Can't open $0.png: $!\n"; print OUTPUT $gd_image->png(); close(OUTPUT);

I'm not really a human, but I play one on earth. flash japh

Replies are listed 'Best First'.
Re^2: Help with GD::Graph
by jeiku (Acolyte) on May 12, 2006 at 04:47 UTC
    Thanks for the replies! Hmmm, not sure what I'm doing wrong now.. I tried that but the graph is kinda screwed.
    #!/usr/bin/perl use GD::Graph::lines; use strict; my $i = ""; open(DATA, "newdata.txt") or die "Cannot open for reading: $!\n"; my @newdata = <DATA>; close(DATA); my @graph_data = [ ['May 12', 'May 13'], [], [], [] ]; for($i = 0; $i < scalar($#newdata + 1); $i++) { my ($celcius, $radiation, $time) = split(/ /, $newdata[$i]); $graph_data[1][$i] = $celcius; $graph_data[2][$i] = $radiation; $graph_data[3][$i] = $time; } my $mygraph = GD::Graph::lines->new(600, 300); $mygraph->set( x_label => 'Time', y_label => 'Value', title => 'Temperature and Radiation', x_labels_vertical => 1, x_label_skip => 50, line_types => [1, 1], line_width => 2, dclrs => ['blue', 'green'], ) or warn $mygraph->error; $mygraph->set_legend_font(GD::gdMediumBoldFont); $mygraph->set_legend('Temperature', 'Radiation'); my $myimage = $mygraph->plot(\@graph_data) or die $mygraph->error; open(GRAPH, ">graph.png"); print GRAPH $myimage->png; close(GRAPH);
    newdata.txt:
    36 85 13:37 36 86 13:38
    Man I suck at Perl :/
      You are on the right track, just making some dereferencing mistakes, and the big x_label_skip value. I'll post a better example later, if you don't figure it out.

      I'm not really a human, but I play one on earth. flash japh
      Try this. I will say, that you are going to run into a problem of having too many x values for the width of the graph, then you need to adjust this x_label_skip value to condense it. A Tk canvas would be a nice way to do this. You could plot every value on a scrolled canvas, and scroll to the current time(or time of interest). Of course if it's for the web, Tk won't help.
      #!/usr/bin/perl use warnings; use GD::Graph::lines; use strict; my @time; my @temp; my @rad; while(my $line = <DATA>){ chomp $line; my ($celcius, $radiation, $time) = split(/ /, $line); push @temp, $celcius; push @rad, $radiation; push @time, $time; } my $graph_data = [ [@time], # X-values [@rad], # Y-value 1 [@temp], #Y-value 2 reference line ]; my $mygraph = GD::Graph::lines->new(600, 300); $mygraph->set( transparent => '0', bgclr => 'white', boxclr => 'lgray', fgclr => 'white', x_label => 'Time', y_label => 'Value', title => 'Temperature and Radiation', x_labels_vertical => 1, # x_label_skip => 1, # line_types => [1, 1], line_width => 2, dclrs => ['blue', 'green'], ) or warn $mygraph->error; $mygraph->set_legend_font(GD::gdLargeFont); $mygraph->set_legend('Radiation','Temperature'); my $myimage = $mygraph->plot($graph_data) or die $mygraph->error; open(GRAPH, ">$0.png"); print GRAPH $myimage->png; close(GRAPH); __END__ 36 85 13:37 36 86 13:38 37 85 13:39 37 86 13:40 38 85 13:41 38 86 13:42 38 85 13:43 39 86 13:44 39 85 13:45 39 88 13:46 39 88 13:47 39 88 13:48 39 88 13:49 39 88 13:50 39 88 13:51 38 87 13:52 38 85 13:53 38 86 13:54 38 85 13:55 38 86 13:56 38 85 13:57 38 86 13:58 37 85 13:59 37 86 14:00 37 85 14:01 37 86 14:02 37 85 14:03 37 86 14:04 37 85 14:05 36 86 14:06 36 85 14:07 36 86 14:08

      I'm not really a human, but I play one on earth. flash japh