Pretty colors for charts using Chart

Monday I was creating a graph for my webshop software. I use the Chart module, but the colors and the graph of the default settings aren't really pretty. So I tried to create a better looking chart. I think I succeeded at least a bit.

Example of the blue and gray chart

Here is the code that I used to get this result:

my $c = Chart::Composite->new(1024, 250);

$c->set(composite_info => [
    [ 'Lines', [1] ],
    [ 'Points', [2] ],
]); 
$c->set(precision    => 0); 
$c->set(skip_x_ticks => 7); 
$c->set(max_y_ticks  => 11);
$c->set(min_y_ticks  => 2); 

$c->set(legend => 'none');
$c->set(grey_background => 'false');
$c->set(y_grid_lines => 'true');

$c->set(colors => { 
    'background' => [255,255,255],
    'misc' => [200,200,200],
    'x_grid_lines' => [220,220,220],
    'y_grid_lines' => [220,220,220],
    'dataset0'=>[150,180,250],
    'dataset1'=>[120,140,240],
}); 


my $label = 'x';
my $val   = 10;
$c->add_pt($label, $val, $val);

You should call add_pt for each point you want to show. I use $val twice because there are two graphs that both need the same value.

I also noticed that setting min_y_ticks to a lower value (default=6) will produce a nicer chart when you have few values.

Welcome

My name is Peter Stuifzand. You're reading my personal website.

Profiles