1 package Imager::Graph::Vertical;
5 Imager::Graph::Vertical- A super class for line/bar/column charts
12 @ISA = qw(Imager::Graph);
14 use constant STARTING_MIN_VALUE => 99999;
17 =item add_data_series(\@data, $series_name)
19 Add a data series to the graph, of the default type.
26 my $series_name = shift;
28 my $series_type = $self->_get_default_series_type();
29 $self->_add_data_series($series_type, $data_ref, $series_name);
34 =item add_column_data_series(\@data, $series_name)
36 Add a column data series to the graph.
40 sub add_column_data_series {
43 my $series_name = shift;
45 $self->_add_data_series('column', $data_ref, $series_name);
50 =item add_stacked_column_data_series(\@data, $series_name)
52 Add a stacked column data series to the graph.
56 sub add_stacked_column_data_series {
59 my $series_name = shift;
61 $self->_add_data_series('stacked_column', $data_ref, $series_name);
66 =item add_line_data_series(\@data, $series_name)
68 Add a line data series to the graph.
72 sub add_line_data_series {
75 my $series_name = shift;
77 $self->_add_data_series('line', $data_ref, $series_name);
82 =item set_y_max($value)
84 Sets the maximum y value to be displayed. This will be ignored if the y_max is lower than the highest value.
89 $_[0]->{'custom_style'}->{'y_max'} = $_[1];
92 =item set_y_min($value)
94 Sets the minimum y value to be displayed. This will be ignored if the y_min is higher than the lowest value.
99 $_[0]->{'custom_style'}->{'y_min'} = $_[1];
102 =item set_range_padding($percentage)
104 Sets the padding to be used, as a percentage. For example, if your data ranges from 0 to 10, and you have a 20 percent padding, the y axis will go to 12.
106 Defaults to 10. This attribute is ignored for positive numbers if set_y_max() has been called, and ignored for negative numbers if set_y_min() has been called.
110 sub set_range_padding {
111 $_[0]->{'custom_style'}->{'range_padding'} = $_[1];
114 =item set_negative_background($color)
116 Sets the background color used below the x axis.
120 sub set_negative_background {
121 $_[0]->{'custom_style'}->{'negative_bg'} = $_[1];
131 my ($self, %opts) = @_;
133 if (!$self->_valid_input()) {
137 $self->_style_setup(\%opts);
139 my $style = $self->{_style};
141 my $img = $self->_get_image()
144 my @image_box = ( 0, 0, $img->getwidth-1, $img->getheight-1 );
145 $self->_set_image_box(\@image_box);
147 my @chart_box = ( 0, 0, $img->getwidth-1, $img->getheight-1 );
148 $self->_draw_legend(\@chart_box);
149 if ($style->{title}{text}) {
150 $self->_draw_title($img, \@chart_box)
154 # Scale the graph box down to the widest graph that can cleanly hold the # of columns.
155 return unless $self->_get_data_range();
156 $self->_remove_tics_from_chart_box(\@chart_box);
157 my $column_count = $self->_get_column_count();
159 my $width = $self->_get_number('width');
160 my $height = $self->_get_number('height');
162 my $graph_width = $chart_box[2] - $chart_box[0];
163 my $graph_height = $chart_box[3] - $chart_box[1];
165 my $col_width = int(($graph_width - 1) / $column_count) -1;
166 $graph_width = $col_width * $column_count + 1;
168 my $tic_count = $self->_get_y_tics();
169 my $tic_distance = int(($graph_height-1) / ($tic_count - 1));
170 $graph_height = $tic_distance * ($tic_count - 1);
172 my $bottom = $chart_box[1];
173 my $left = $chart_box[0];
175 $self->{'_style'}{'graph_width'} = $graph_width;
176 $self->{'_style'}{'graph_height'} = $graph_height;
178 my @graph_box = ($left, $bottom, $left + $graph_width, $bottom + $graph_height);
179 $self->_set_graph_box(\@graph_box);
182 color => $self->_get_color('outline.line'),
184 xmax => $left+$graph_width,
186 ymax => $bottom+$graph_height,
190 color => $self->_get_color('bg'),
192 xmax => $left+$graph_width - 1,
194 ymax => $bottom+$graph_height-1 ,
198 my $min_value = $self->_get_min_value();
199 my $max_value = $self->_get_max_value();
200 my $value_range = $max_value - $min_value;
204 $zero_position = $bottom + $graph_height - (-1*$min_value / $value_range) * ($graph_height-1);
207 if ($min_value < 0) {
209 color => $self->_get_color('negative_bg'),
211 xmax => $left+$graph_width- 1,
212 ymin => $zero_position,
213 ymax => $bottom+$graph_height - 1,
218 y1 => $zero_position,
219 x2 => $left + $graph_width,
220 y2 => $zero_position,
221 color => $self->_get_color('outline.line'),
225 if ($self->_get_data_series()->{'stacked_column'}) {
226 $self->_draw_stacked_columns();
228 if ($self->_get_data_series()->{'column'}) {
229 $self->_draw_columns();
231 if ($self->_get_data_series()->{'line'}) {
232 $self->_draw_lines();
235 if ($self->_get_y_tics()) {
236 $self->_draw_y_tics();
238 if ($self->_get_labels()) {
239 $self->_draw_x_tics();
242 return $self->_get_image();
245 sub _get_data_range {
250 my $column_count = 0;
252 my ($sc_min, $sc_max, $sc_cols) = $self->_get_stacked_column_range();
253 my ($c_min, $c_max, $c_cols) = $self->_get_column_range();
254 my ($l_min, $l_max, $l_cols) = $self->_get_line_range();
256 # These are side by side...
259 $min_value = $self->_min(STARTING_MIN_VALUE, $sc_min, $c_min, $l_min);
260 $max_value = $self->_max(0, $sc_max, $c_max, $l_max);
262 my $config_min = $self->_get_number('y_min');
263 my $config_max = $self->_get_number('y_max');
265 if (defined $config_max && $config_max < $max_value) {
268 if (defined $config_min && $config_min > $min_value) {
272 my $range_padding = $self->_get_number('range_padding');
273 if (defined $config_min) {
274 $min_value = $config_min;
277 if ($min_value > 0) {
280 if ($range_padding && $min_value < 0) {
281 my $difference = $min_value * $range_padding / 100;
282 if ($min_value < -1 && $difference > -1) {
285 $min_value += $difference;
288 if (defined $config_max) {
289 $max_value = $config_max;
292 if ($range_padding && $max_value > 0) {
293 my $difference = $max_value * $range_padding / 100;
294 if ($max_value > 1 && $difference < 1) {
297 $max_value += $difference;
300 $column_count = $self->_max(0, $sc_cols, $l_cols);
302 if ($self->_get_number('automatic_axis')) {
303 # In case this was set via a style, and not by the api method
304 eval { require Chart::Math::Axis; };
306 return $self->_error("Can't use automatic_axis - $@");
309 my $axis = Chart::Math::Axis->new();
310 $axis->add_data($min_value, $max_value);
311 $max_value = $axis->top;
312 $min_value = $axis->bottom;
313 my $ticks = $axis->ticks;
314 # The +1 is there because we have the bottom tick as well
315 $self->set_y_tics($ticks+1);
318 $self->_set_max_value($max_value);
319 $self->_set_min_value($min_value);
320 $self->_set_column_count($column_count);
329 foreach my $value (@_) {
330 next unless defined $value;
331 if ($value < $min) { $min = $value; }
340 foreach my $value (@_) {
341 next unless defined $value;
342 if ($value > $min) { $min = $value; }
347 sub _get_line_range {
349 my $series = $self->_get_data_series()->{'line'};
350 return (undef, undef, 0) unless $series;
353 my $min_value = STARTING_MIN_VALUE;
354 my $column_count = 0;
356 my @series = @{$series};
357 foreach my $series (@series) {
358 my @data = @{$series->{'data'}};
360 if (scalar @data > $column_count) {
361 $column_count = scalar @data;
364 foreach my $value (@data) {
365 if ($value > $max_value) { $max_value = $value; }
366 if ($value < $min_value) { $min_value = $value; }
370 return ($min_value, $max_value, $column_count);
373 sub _get_column_range {
376 my $series = $self->_get_data_series()->{'column'};
377 return (undef, undef, 0) unless $series;
380 my $min_value = STARTING_MIN_VALUE;
381 my $column_count = 0;
383 my @series = @{$series};
384 foreach my $series (@series) {
385 my @data = @{$series->{'data'}};
387 foreach my $value (@data) {
389 if ($value > $max_value) { $max_value = $value; }
390 if ($value < $min_value) { $min_value = $value; }
394 return ($min_value, $max_value, $column_count);
397 sub _get_stacked_column_range {
401 my $min_value = STARTING_MIN_VALUE;
402 my $column_count = 0;
404 return (undef, undef, 0) unless $self->_get_data_series()->{'stacked_column'};
405 my @series = @{$self->_get_data_series()->{'stacked_column'}};
409 for (my $i = scalar @series - 1; $i >= 0; $i--) {
410 my $series = $series[$i];
411 my $data = $series->{'data'};
413 for (my $i = 0; $i < scalar @$data; $i++) {
415 if ($data->[$i] > 0) {
416 $value = $data->[$i] + ($max_entries[$i] || 0);
417 $data->[$i] = $value;
418 $max_entries[$i] = $value;
420 elsif ($data->[$i] < 0) {
421 $value = $data->[$i] + ($min_entries[$i] || 0);
422 $data->[$i] = $value;
423 $min_entries[$i] = $value;
425 if ($value > $max_value) { $max_value = $value; }
426 if ($value < $min_value) { $min_value = $value; }
428 if (scalar @$data > $column_count) {
429 $column_count = scalar @$data;
433 return ($min_value, $max_value, $column_count);
438 my $chart_box = shift;
439 my $style = $self->{'_style'};
442 my $img = $self->_get_image();
443 if (my $series = $self->_get_data_series()->{'stacked_column'}) {
444 push @labels, map { $_->{'series_name'} } @$series;
446 if (my $series = $self->_get_data_series()->{'column'}) {
447 push @labels, map { $_->{'series_name'} } @$series;
449 if (my $series = $self->_get_data_series()->{'line'}) {
450 push @labels, map { $_->{'series_name'} } @$series;
453 if ($style->{features}{legend} && (scalar @labels)) {
454 $self->SUPER::_draw_legend($self->_get_image(), \@labels, $chart_box)
460 sub _draw_flat_legend {
466 my $style = $self->{'_style'};
468 my $img = $self->_get_image();
470 my $max_value = $self->_get_max_value();
471 my $min_value = $self->_get_min_value();
472 my $column_count = $self->_get_column_count();
474 my $value_range = $max_value - $min_value;
476 my $width = $self->_get_number('width');
477 my $height = $self->_get_number('height');
479 my $graph_width = $self->_get_number('graph_width');
480 my $graph_height = $self->_get_number('graph_height');
482 my $line_series = $self->_get_data_series()->{'line'};
483 my $series_counter = $self->_get_series_counter() || 0;
485 my $has_columns = (defined $self->_get_data_series()->{'column'} || $self->_get_data_series->{'stacked_column'}) ? 1 : 0;
487 my $col_width = int($graph_width / $column_count) -1;
489 my $graph_box = $self->_get_graph_box();
490 my $left = $graph_box->[0] + 1;
491 my $bottom = $graph_box->[1];
493 my $zero_position = $bottom + $graph_height - (-1*$min_value / $value_range) * ($graph_height - 1);
496 my $line_aa = $self->_get_number("lineaa");
497 foreach my $series (@$line_series) {
498 my @data = @{$series->{'data'}};
499 my $data_size = scalar @data;
503 $interval = $graph_width / ($data_size);
506 $interval = $graph_width / ($data_size - 1);
508 my $color = $self->_data_color($series_counter);
510 # We need to add these last, otherwise the next line segment will overwrite half of the marker
511 my @marker_positions;
512 for (my $i = 0; $i < $data_size - 1; $i++) {
513 my $x1 = $left + $i * $interval;
514 my $x2 = $left + ($i + 1) * $interval;
516 $x1 += $has_columns * $interval / 2;
517 $x2 += $has_columns * $interval / 2;
519 my $y1 = $bottom + ($value_range - $data[$i] + $min_value)/$value_range * $graph_height;
520 my $y2 = $bottom + ($value_range - $data[$i + 1] + $min_value)/$value_range * $graph_height;
522 push @marker_positions, [$x1, $y1];
523 $img->line(x1 => $x1, y1 => $y1, x2 => $x2, y2 => $y2, aa => $line_aa, color => $color) || die $img->errstr;
526 my $x2 = $left + ($data_size - 1) * $interval;
527 $x2 += $has_columns * $interval / 2;
529 my $y2 = $bottom + ($value_range - $data[$data_size - 1] + $min_value)/$value_range * $graph_height;
531 push @marker_positions, [$x2, $y2];
532 foreach my $position (@marker_positions) {
533 $self->_draw_line_marker($position->[0], $position->[1], $series_counter);
538 $self->_set_series_counter($series_counter);
543 my ($self, $index) = @_;
545 my $markers = $self->{'_style'}{'line_markers'};
549 my $marker = $markers->[$index % @$markers];
554 sub _draw_line_marker {
556 my ($x1, $y1, $series_counter) = @_;
558 my $img = $self->_get_image();
560 my $style = $self->_line_marker($series_counter);
561 return unless $style;
563 my $type = $style->{'shape'};
564 my $radius = $style->{'radius'};
566 my $line_aa = $self->_get_number("lineaa");
567 my $fill_aa = $self->_get_number("fill.aa");
568 if ($type eq 'circle') {
569 my @fill = $self->_data_fill($series_counter, [$x1 - $radius, $y1 - $radius, $x1 + $radius, $y1 + $radius]);
570 $img->circle(x => $x1, y => $y1, r => $radius, aa => $fill_aa, filled => 1, @fill);
572 elsif ($type eq 'square') {
573 my @fill = $self->_data_fill($series_counter, [$x1 - $radius, $y1 - $radius, $x1 + $radius, $y1 + $radius]);
574 $img->box(xmin => $x1 - $radius, ymin => $y1 - $radius, xmax => $x1 + $radius, ymax => $y1 + $radius, @fill);
576 elsif ($type eq 'diamond') {
577 # The gradient really doesn't work for diamond
578 my $color = $self->_data_color($series_counter);
581 [$x1 - $radius, $y1],
582 [$x1, $y1 + $radius],
583 [$x1 + $radius, $y1],
584 [$x1, $y1 - $radius],
586 filled => 1, color => $color, aa => $fill_aa);
588 elsif ($type eq 'triangle') {
589 # The gradient really doesn't work for triangle
590 my $color = $self->_data_color($series_counter);
593 [$x1 - $radius, $y1 + $radius],
594 [$x1 + $radius, $y1 + $radius],
595 [$x1, $y1 - $radius],
597 filled => 1, color => $color, aa => $fill_aa);
600 elsif ($type eq 'x') {
601 my $color = $self->_data_color($series_counter);
602 $img->line(x1 => $x1 - $radius, y1 => $y1 -$radius, x2 => $x1 + $radius, y2 => $y1+$radius, aa => $line_aa, color => $color) || die $img->errstr;
603 $img->line(x1 => $x1 + $radius, y1 => $y1 -$radius, x2 => $x1 - $radius, y2 => $y1+$radius, aa => $line_aa, color => $color) || die $img->errstr;
605 elsif ($type eq 'plus') {
606 my $color = $self->_data_color($series_counter);
607 $img->line(x1 => $x1, y1 => $y1 -$radius, x2 => $x1, y2 => $y1+$radius, aa => $line_aa, color => $color) || die $img->errstr;
608 $img->line(x1 => $x1 + $radius, y1 => $y1, x2 => $x1 - $radius, y2 => $y1, aa => $line_aa, color => $color) || die $img->errstr;
614 my $style = $self->{'_style'};
616 my $img = $self->_get_image();
618 my $max_value = $self->_get_max_value();
619 my $min_value = $self->_get_min_value();
620 my $column_count = $self->_get_column_count();
622 my $value_range = $max_value - $min_value;
624 my $width = $self->_get_number('width');
625 my $height = $self->_get_number('height');
627 my $graph_width = $self->_get_number('graph_width');
628 my $graph_height = $self->_get_number('graph_height');
631 my $graph_box = $self->_get_graph_box();
632 my $left = $graph_box->[0] + 1;
633 my $bottom = $graph_box->[1];
634 my $zero_position = int($bottom + $graph_height - (-1*$min_value / $value_range) * ($graph_height -1));
636 my $bar_width = int($graph_width / $column_count - 1);
639 if ($style->{'features'}{'outline'}) {
640 $outline_color = $self->_get_color('outline.line');
643 my $series_counter = $self->_get_series_counter() || 0;
644 my $col_series = $self->_get_data_series()->{'column'};
646 # This tracks the series we're in relative to the starting series - this way colors stay accurate, but the columns don't start out too far to the right.
647 my $column_series = 0;
649 # If there are stacked columns, non-stacked columns need to start one to the right of where they would otherwise
650 my $has_stacked_columns = (defined $self->_get_data_series()->{'stacked_column'} ? 1 : 0);
652 for (my $series_pos = 0; $series_pos < scalar @$col_series; $series_pos++) {
653 my $series = $col_series->[$series_pos];
654 my @data = @{$series->{'data'}};
655 my $data_size = scalar @data;
656 my $color = $self->_data_color($series_counter);
657 for (my $i = 0; $i < $data_size; $i++) {
658 my $x1 = int($left + $bar_width * (scalar @$col_series * $i + $series_pos)) + scalar @$col_series * $i + $series_pos;
659 if ($has_stacked_columns) {
660 $x1 += ($i + 1) * $bar_width + $i + 1;
662 my $x2 = $x1 + $bar_width;
664 my $y1 = int($bottom + ($value_range - $data[$i] + $min_value)/$value_range * $graph_height);
666 my $color = $self->_data_color($series_counter);
668 # my @fill = $self->_data_fill($series_counter, [$x1, $y1, $x2, $zero_position]);
670 $img->box(xmin => $x1, xmax => $x2, ymin => $y1, ymax => $zero_position-1, color => $color, filled => 1);
671 if ($style->{'features'}{'outline'}) {
672 $img->box(xmin => $x1, xmax => $x2, ymin => $y1, ymax => $zero_position, color => $outline_color);
676 $img->box(xmin => $x1, xmax => $x2, ymin => $zero_position+1, ymax => $y1, color => $color, filled => 1);
677 if ($style->{'features'}{'outline'}) {
678 $img->box(xmin => $x1, xmax => $x2, ymin => $zero_position+1, ymax => $y1+1, color => $outline_color);
686 $self->_set_series_counter($series_counter);
690 sub _draw_stacked_columns {
692 my $style = $self->{'_style'};
694 my $img = $self->_get_image();
696 my $max_value = $self->_get_max_value();
697 my $min_value = $self->_get_min_value();
698 my $column_count = $self->_get_column_count();
699 my $value_range = $max_value - $min_value;
701 my $graph_box = $self->_get_graph_box();
702 my $left = $graph_box->[0] + 1;
703 my $bottom = $graph_box->[1];
705 my $graph_width = $self->_get_number('graph_width');
706 my $graph_height = $self->_get_number('graph_height');
708 my $bar_width = int($graph_width / $column_count -1);
709 my $column_series = 0;
710 if (my $column_series_data = $self->_get_data_series()->{'column'}) {
711 $column_series = (scalar @$column_series_data);
716 if ($style->{'features'}{'outline'}) {
717 $outline_color = $self->_get_color('outline.line');
720 my $zero_position = $bottom + $graph_height - (-1*$min_value / $value_range) * ($graph_height -1);
721 my $col_series = $self->_get_data_series()->{'stacked_column'};
722 my $series_counter = $self->_get_series_counter() || 0;
723 foreach my $series (@$col_series) {
724 my @data = @{$series->{'data'}};
725 my $data_size = scalar @data;
726 my $color = $self->_data_color($series_counter);
727 for (my $i = 0; $i < $data_size; $i++) {
728 my $x1 = int($left + $bar_width * ($column_series * $i)) + $column_series * $i;
729 my $x2 = $x1 + $bar_width;
731 my $y1 = $bottom + ($value_range - $data[$i] + $min_value)/$value_range * $graph_height;
734 $img->box(xmin => $x1, xmax => $x2, ymin => $y1, ymax => $zero_position-1, color => $color, filled => 1);
735 if ($style->{'features'}{'outline'}) {
736 $img->box(xmin => $x1, xmax => $x2, ymin => $y1, ymax => $zero_position, color => $outline_color);
740 $img->box(xmin => $x1, xmax => $x2, ymin => $zero_position+1, ymax => $y1, color => $color, filled => 1);
741 if ($style->{'features'}{'outline'}) {
742 $img->box(xmin => $x1, xmax => $x2, ymin => $zero_position+1, ymax => $y1+1, color => $outline_color);
749 $self->_set_series_counter($series_counter);
753 sub _add_data_series {
755 my $series_type = shift;
756 my $data_ref = shift;
757 my $series_name = shift;
759 my $graph_data = $self->{'graph_data'} || {};
761 my $series = $graph_data->{$series_type} || [];
763 push @$series, { data => $data_ref, series_name => $series_name };
765 $graph_data->{$series_type} = $series;
767 $self->{'graph_data'} = $graph_data;
773 =item show_horizontal_gridlines()
775 Shows horizontal gridlines at the y-tics.
779 sub show_horizontal_gridlines {
780 $_[0]->{'custom_style'}->{'horizontal_gridlines'} = 1;
783 =item use_automatic_axis()
785 Automatically scale the Y axis, based on L<Chart::Math::Axis>. If Chart::Math::Axis isn't installed, this sets an error and returns undef. Returns 1 if it is installed.
789 sub use_automatic_axis {
790 eval { require Chart::Math::Axis; };
792 return $_[0]->_error("use_automatic_axis - $@\nCalled from ".join(' ', caller)."\n");
794 $_[0]->{'custom_style'}->{'automatic_axis'} = 1;
799 =item set_y_tics($count)
801 Set the number of Y tics to use. Their value and position will be determined by the data range.
806 $_[0]->{'y_tics'} = $_[1];
810 return $_[0]->{'y_tics'} || 0;
813 sub _remove_tics_from_chart_box {
815 my $chart_box = shift;
818 my $tic_width = $self->_get_y_tic_width() || 10;
819 my @y_tic_box = ($chart_box->[0], $chart_box->[1], $chart_box->[0] + $tic_width, $chart_box->[3]);
822 my $tic_height = $self->_get_x_tic_height() || 10;
823 my @x_tic_box = ($chart_box->[0], $chart_box->[3] - $tic_height, $chart_box->[2], $chart_box->[3]);
825 $self->_remove_box($chart_box, \@y_tic_box);
826 $self->_remove_box($chart_box, \@x_tic_box);
829 sub _get_y_tic_width{
831 my $min = $self->_get_min_value();
832 my $max = $self->_get_max_value();
833 my $tic_count = $self->_get_y_tics();
835 my $img = $self->_get_image();
836 my $graph_box = $self->_get_graph_box();
837 my $image_box = $self->_get_image_box();
839 my $interval = ($max - $min) / ($tic_count - 1);
841 my %text_info = $self->_text_style('legend')
845 for my $count (0 .. $tic_count - 1) {
846 my $value = sprintf("%.2f", ($count*$interval)+$min);
848 my @box = $self->_text_bbox($value, 'legend');
849 my $width = $box[2] - $box[0];
853 if ($width > $max_width) {
861 sub _get_x_tic_height {
864 my $labels = $self->_get_labels();
866 my $tic_count = (scalar @$labels) - 1;
868 my %text_info = $self->_text_style('legend')
872 for my $count (0 .. $tic_count) {
873 my $label = $labels->[$count];
875 my @box = $self->_text_bbox($label, 'legend');
877 my $height = $box[3] - $box[1];
881 if ($height > $max_height) {
882 $max_height = $height;
891 my $min = $self->_get_min_value();
892 my $max = $self->_get_max_value();
893 my $tic_count = $self->_get_y_tics();
895 my $img = $self->_get_image();
896 my $graph_box = $self->_get_graph_box();
897 my $image_box = $self->_get_image_box();
899 my $interval = ($max - $min) / ($tic_count - 1);
901 my %text_info = $self->_text_style('legend')
904 my $show_gridlines = $self->_get_number('horizontal_gridlines');
905 my $tic_distance = int(($graph_box->[3] - $graph_box->[1]) / ($tic_count - 1));
906 for my $count (0 .. $tic_count - 1) {
907 my $x1 = $graph_box->[0] - 5;
908 my $x2 = $graph_box->[0] + 5;
909 my $y1 = $graph_box->[3] - ($count * $tic_distance);
911 my $value = ($count*$interval)+$min;
912 if ($interval < 1 || ($value != int($value))) {
913 $value = sprintf("%.2f", $value);
916 my @box = $self->_text_bbox($value, 'legend')
919 $img->line(x1 => $x1, x2 => $x2, y1 => $y1, y2 => $y1, aa => 1, color => '000000');
922 my $height = $box[3];
924 $img->string(%text_info,
925 x => ($x1 - $width - 3),
926 y => ($y1 + ($height / 2)),
930 if ($show_gridlines) {
932 for (my $i = $graph_box->[0]; $i < $graph_box->[2]; $i += 6) {
935 if ($x2 > $graph_box->[2]) { $x2 = $graph_box->[2]; }
936 $img->line(x1 => $x1, x2 => $x2, y1 => $y1, y2 => $y1, aa => 1, color => '000000');
946 my $img = $self->_get_image();
947 my $graph_box = $self->_get_graph_box();
948 my $image_box = $self->_get_image_box();
950 my $labels = $self->_get_labels();
952 my $tic_count = (scalar @$labels) - 1;
954 my $has_columns = (defined $self->_get_data_series()->{'column'} || defined $self->_get_data_series()->{'stacked_column'});
956 # If we have columns, we want the x-ticks to show up in the middle of the column, not on the left edge
957 my $denominator = $tic_count;
961 my $tic_distance = ($graph_box->[2] - $graph_box->[0]) / ($denominator);
962 my %text_info = $self->_text_style('legend')
965 for my $count (0 .. $tic_count) {
966 my $label = $labels->[$count];
967 my $x1 = $graph_box->[0] + ($tic_distance * $count);
970 $x1 += $tic_distance / 2;
972 my $y1 = $graph_box->[3] + 5;
973 my $y2 = $graph_box->[3] - 5;
975 $img->line(x1 => $x1, x2 => $x1, y1 => $y1, y2 => $y2, aa => 1, color => '000000');
977 my @box = $self->_text_bbox($label, 'legend')
981 my $height = $box[3];
983 $img->string(%text_info,
984 x => ($x1 - ($width / 2)),
985 y => ($y1 + ($height + 5)),
995 if (!defined $self->_get_data_series() || !keys %{$self->_get_data_series()}) {
996 return $self->_error("No data supplied");
999 my $data = $self->_get_data_series();
1000 if (defined $data->{'line'} && !scalar @{$data->{'line'}->[0]->{'data'}}) {
1001 return $self->_error("No values in data series");
1003 if (defined $data->{'column'} && !scalar @{$data->{'column'}->[0]->{'data'}}) {
1004 return $self->_error("No values in data series");
1006 if (defined $data->{'stacked_column'} && !scalar @{$data->{'stacked_column'}->[0]->{'data'}}) {
1007 return $self->_error("No values in data series");
1013 sub _set_column_count { $_[0]->{'column_count'} = $_[1]; }
1014 sub _set_min_value { $_[0]->{'min_value'} = $_[1]; }
1015 sub _set_max_value { $_[0]->{'max_value'} = $_[1]; }
1016 sub _set_image_box { $_[0]->{'image_box'} = $_[1]; }
1017 sub _set_graph_box { $_[0]->{'graph_box'} = $_[1]; }
1018 sub _set_series_counter { $_[0]->{'series_counter'} = $_[1]; }
1019 sub _get_column_count { return $_[0]->{'column_count'} }
1020 sub _get_min_value { return $_[0]->{'min_value'} }
1021 sub _get_max_value { return $_[0]->{'max_value'} }
1022 sub _get_image_box { return $_[0]->{'image_box'} }
1023 sub _get_graph_box { return $_[0]->{'graph_box'} }
1024 sub _get_series_counter { return $_[0]->{'series_counter'} }