in reply to draw picture by google Chart

There's a lot about your post I don't understand, and I have no experience whatever with the URI::GoogleChart module, but I have never thought that mere ignorance should prevent one from offering advice, so here goes.

First off, I assume the

my $chart = URI::GoogleChart->new("lines", 300, 100, data => [45, 80, 55, 68], range_show => "left", range_round => 1, );
statement works as it stands (possibly an example from documentation), and your problem is to use different data than 45, 80, 55, 68.

... my data is an array or array_ref without comma, like: @a = (1 2 3 4) ...

As you have seen, this doesn't work because it is syntactically incorrect. The correct assignment expression would be  @a = (1, 2, 3, 4) or perhaps a statement like
    my @a = (1, 2, 3, 4);
if one were defining a lexical array (see my) and initializing it. The quick fix is to put in the needed commas.

But I suspect the quick fix doesn't work because your data is not in the form of a list, but rather is a string consisting of numbers with whitespace separating the numbers, something like  "1 2 3 4" (with the  " double-quotes being an essential part of the expression), e.g.,
    my $data = "1 2 3 4";

If so, the question becomes "How do I convert a string in the format '1 2 3 4' into a list that I can assign to an array?" The split Perl built-in function can do just this with a string in this format. (Use something like Data::Dumper or Data::Dump to confirm your intermediate results.)

>perl -wMstrict -le "use Data::Dumper; ;; my $data = '1 2 3 4'; my @a = split /\s+/, $data; print Dumper \@a; " $VAR1 = [ '1', '2', '3', '4' ];

Now you have an array from which you can take a reference:  my $array_ref = \@a;
This reference could be used in the  new() constructor of URI::GoogleChart:  data => $array_ref,
or else the result of the referencing operation could be used directly:  data => \@a,
or else the array itself could be expanded within an anonymous array constructor:  data => [ @a ],

I hope that helps. Update: Oh, and please pay attention to kcott's good advice about effective question-posting and the use of strict and warnings!

Replies are listed 'Best First'.
Re^2: draw picture by google Chart
by HHCHANG (Novice) on Oct 27, 2013 at 06:58 UTC

    it's my fault. I should describe it more clearly.

    I know where is the problem.

    I parse a text and want to get identical words and its times. So I have a hash: key is "identical words" and value is "times".

    I hope I could draw a lines picture (x-axis is identical word and y-axis is times). In other words, "times" is data argument and "identical words" is chxl argument in URI::GoogleChart.

    my ($x, @y); $x="0:"; foreach (sort { $word2_hash{$b} <=> $word2_hash{$a} or $a cmp $b} +keys %word2_hash) { $x .= "|$_"; #add identical words push @y, $word2_hash{$_}; #add times } my $chart = URI::GoogleChart->new("lines", 400, 150, data => \@y,#it is OK to parse array_ref range_show => "left", range_round => 1, color => ["red"], chxl => "$x", # chxt => "x", ); #getstore($chart, "chart.png"); #print "get pic\n";

    <Sorry for my wrong post. It could work if use array_ref/p>

    I find where is my problem. The chxl seems have limit. If I decrease the identical words. I can get the picture. If I use a lot of identical words, I couldn't get the picture.

    Thanks for all your reply.