in reply to Help With GD::Graph::lines

This is th code I am using:
use GD::Graph::lines; @data = ( ["1st","2nd","3rd","4th","5th","6th","7th", "8th", "9th"], [ 1, 2, 5, 6, 3, 1.5, 1, 3, 4], [ sort { $a <=> $b } (1, 2, 5, 6, 3, 1.5, 1, 3, 4) ] ); my $graph = GD::Graph::lines->new(400,400); $graph->set ( x_label => 'values1', y_label => 'values2', title => 'Correlate', ) or die $my_graph->error; my $gd = $graph->plot(\@data) or die $my_graph->error; open (IMG, '>file.png') or die $!; binmode IMG; print IMG $gd->png;
The line always start at 1st but I need it to start drawing at the origin. Any help would be appreciated.

Thanks.

Replies are listed 'Best First'.
Re^2: Help With GD::Graph::lines
by Anonymous Monk on Aug 01, 2007 at 02:30 UTC

    sorry, I meant to use <br> new line and not <b> for bold

    This is th code I am using:

    use GD::Graph::lines; @data = ( "1st","2nd","3rd","4th","5th","6th","7th", "8th", "9th", 1, 2, 5, 6, 3, 1.5, 1, 3, 4, sort { $a <=> $b } (1, 2, 5, 6, 3, 1.5, 1, 3, 4) ); my $graph = GD::Graph::lines->new(400,400); $graph->set ( x_label => 'values1', y_label => 'values2', title => 'Correlate', ) or die $my_graph->error; my $gd = $graph->plot(\@data) or die $my_graph->error; open (IMG, '>file.png') or die $!; binmode IMG; print IMG $gd->png;

    The line always start at 1st but I need it to start drawing at the origin. Any help would be appreciated. Thanks.

    Code tags added by GrandFather

      Try prefixing your value sets with zeros.

      use GD::Graph::lines; @data = ( [ '0', "1st","2nd","3rd","4th","5th","6th","7th", "8th", "9th", ], [ 0, 1, 2, 5, 6, 3, 1.5, 1, 3, 4, ], [ 0, sort { $a <=> $b } (1, 2, 5, 6, 3, 1.5, 1, 3, 4) ], ); my $graph = GD::Graph::lines->new(400,400); $graph->set ( x_label => 'values1', y_label => 'values2', title => 'Correlate', ) or die $!; my $gd = $graph->plot(\@data) or die $!; open (IMG, '>file.png') or die $!; binmode IMG; print IMG $gd->png; close IMG;

      Also, please read the formatting guidelines next time you post.


      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      "Science is about questioning the status quo. Questioning authority".
      In the absence of evidence, opinion is indistinguishable from prejudice.
        Thanks but this did not work. What it did was created another tick on the x-axis name 0 and then 1st, 2nd, .... and so on. Now my x-axis has two 0's, one at the origin and one for the new 0 we just added.
      Guess it's got to do with the type of data you use. 1st is only the first appearance of the data. Therefor it'll not start at zero. Maybe a bar chart is more natural?

      A site you might think is interesting:
      http://gdgraph.com/samples/sample11.html

      Gert
        Thanks.
        This piece of code at your referred site was able to place the start of the plot at the origin but I am not sure how they did it.
        use strict;
        use GD::Graph::lines;
        require 'save.pl';
        use constant PI => 4 * atan2(1,1);
        print STDERR "Processing sample55\n";
        my @x = map {$_ * 3 * PI/100} (0 .. 100);
        my @y = map sin, @x;
        my @z = map cos, @x;
        my @data = (\@x,\@y,\@z);
        my $my_graph = new GD::Graph::lines();
        $my_graph->set(
        x_label => 'Angle (Radians)',
        y_label => 'Trig Function Value',
        x_tick_number => 'auto',
        y_tick_number => 'auto',
        title => 'Sine and Cosine',
        line_width => 1,
        x_label_position => 1/2,
        r_margin => 15,
        transparent => 0,
        );
        $my_graph->set_legend('Thanks to Scott Prahl');
        $my_graph->plot(\@data);
        save_chart($my_graph, 'sample55');