[ic] Graphics plot in interchange ?

Davor Ocelic docelic at spinlocksolutions.com
Wed Sep 3 11:16:07 UTC 2008

On Wed, 03 Sep 2008 08:58:35 +0200
Marco Mescoli <m.mescoli at omnib.it> wrote:

> Dear list
> any suggestion for perl modules to use inside IC enviro to develop 
> simple bar graph and display in html pages ?

Hey what up,

I used bargraph script for this, which is an extended wrapper over

Bargraph is on

So here's how it works here:

1) My IC page prepares the config file for bargraph (it contains both
plot config lines and actual plot data):

[perl tables=tbl1]

    # Graphing

   # set plot options
   my $data =<<__EOD__;
title=Inhabitants structure for years $years
xlabel=Age group
ylabel=Nr. of inhabitants
extraops=set size 2.1,1.8

# Add data to plot
    for (my $i=0; $i<@age_groups; $i++) {
        $data .= "\n$age_groups[$i] ";
        for (my $j=0;$j<@years;$j++) {
            $data .= "$ydata[$j][$i+1] ";
        $data .= "\n";


2) I save this $data to tmp file in CATALOG/tmp/$session/gnuplot:

        'tmp/' . $Tag->data(qw/session id/) . '/gnuplot',
        $data );

    $Scratch->{years} = join ',', @years;



3) I display graph with:

 <img src=/images/[gnp years="[scratch years]" session="[data session id]"] />

[gnp] is a global usertag which calls bargraph script and passes it the 
generated config file. Bargraph calls gnuplot which produces the plot and saves
it to the corresponding image file and returns the file name:

UserTag gnp AddAttr
UserTag gnp Routine <<EOR
use Chart::Graph::Gnuplot qw(gnuplot);
sub {

    my $opt = shift;
    ( my $filename = $opt->{years} ) =~ s/ /,/g;
    my $session = $opt->{session};

    $filename = '/PATH-TO/graph-' . $filename;
    ( my $relative = $filename ) =~ s#.*/##;

    unless ( -r "$filename.png" ) {
        system("/usr/local/bin/bargraph.pl /PATH-TO/cat/tmp/$session/gnuplot > $filename.eps")
            and return "$@";
        system("convert $filename.eps $filename.png") and return "$@";
        system("chmod 755 $filename.eps $filename.png") and return "$@";

    $relative . '.png'

You notice that gnp tag calls bargraph.pl, which comes from
bargraph package.

Also, you see that bargraph outputs eps in my case, which I convert
to png (using 'convert' command from imagemagick package), but you
can pass -png to bargraph to have png right away.


More information about the interchange-users mailing list