1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655
|
=encoding UTF-8
=head1 NAME
Chart::Manual::Types - all chart types by example
=head1 OVERVIEW
This page illustrates all supported chart types, describes their
special abilities and programming needs. Detailled information is linked
whenever possible.
Currently available are xycharts with points, lines, mountains,
bar charts, stacked bars, error bars, pie and ring charts with split and
polar coordinate systems. Also composite charts are possible.
Generally, each chart type here is implementd by a class: Chart::* (name),
which inherits most of its methods from Chart::Base. Every
L<constructor|Chart::Manual::Methods/new> takes two arguments,
which are width and height of the later generated image.
=head2 Bars
=for HTML <p>
<img src="https://raw.githubusercontent.com/lichtkind/Chart/main/dev/example/manual/bars.png" alt="dual bar chart" width="500" height="300">
</p>
The class Chart::Bars creates a chart made up of a series of vertical bars.
The length of each bar depicts one value of your second data set.
The first data set however, defines the domain. In this example the first
value of the first (domain) data set is 'camel'. So the first value of
the second set (300) is positioned above the first tick on the x-axis
labeled 'camel'. Right beside it is a differently colored bar, depticting
the first value of the third data set (800). Since the option L<spaced_bars|Chart::Manual::Properties/spaced_bars>
is set to C<'true'> on default, both bars are separated from the next group of bars.
In this example it also makes also sense to activate the horizontal
L<y_grid_lines|Chart::Manual::Properties/y_grid_lines> and give them
a subtle color. Further important was it to set the property L<min_val|Chart::Manual::Properties/min_val>
to zero, so that the bars could be seen in full length and not from
the min value of the data sets (300) on upwards. L<precision|Chart::Manual::Properties/precision>
set to zero just drops the decimals on the tick label so the chart looks
a little cleaner. All the the other color set serv the same purpose.
use Chart::Bars;
my $g = Chart::Bars->new( 500, 300 );
$g->add_dataset( qw/ camel cat dog bear shell/ );
$g->add_dataset( 300, 400, 800, 500, 900 );
$g->add_dataset( 800, 600, 300, 300, 400 );
$g->set(
title => 'Bars !',
x_label => 'Group',
y_label => 'Value',
y_grid_lines => 'true',
colors => {
y_grid_lines => 'gray70',
misc => 'gray55',
text => 'gray55',
x_label => 'gray40',
y_label => 'gray40',
title => 'gray20',
},
min_val => 0,
precision => 0,
# spaced_bars => 'false',
);
$g->png("bars.png");
=head2 Composite
=for HTML <p>
<img src="https://raw.githubusercontent.com/lichtkind/Chart/main/dev/example/manual/composite.png" alt="composite chart">
</p>
The class Chart::Composite creates a two component chart with two
types of charts which are layered one above each other. Just set
the option composite info. For example, you can create a two
component chart with bars and lines. A composite chart does not
make sense with all combinations of chart types, but it works pretty
good with Lines, Points, LinesPoints and Bars. Note that two similar
chart types may come into visual conflict. Chart::Composite can do
only composite charts made up of two components.
In this example are the data sets one and two displayed as L</Bars> and
the next two als L</LinesPoints> as set by the property
L<composite_info|Chart::Manual::Properties/composite_info>.
Please read these sections too. Otherwise we only colored the last data
set for better contrast und cut the decimals from the axis labels via
L<precision|Chart::Manual::Properties/precision>.
use Chart::Composite;
my $g = Chart::Composite->new( );
$g->add_dataset( 1, 2, 3 );
$g->add_dataset( 10, 20, 30 );
$g->add_dataset( 15, 25, 32 );
$g->add_dataset( 7, 24, 23 );
$g->add_dataset( 5.1, 7.5, 9.9 );
$g->set(
title => 'Composite Chart',
composite_info => [ [ 'Bars', [ 1, 2 ] ],
[ 'LinesPoints', [ 3, 4 ] ] ],
include_zero => 'true',
precision => 0,
colors => {
dataset3 => 'darkorange',
}
);
$g->png("composite.png");
=head2 Direction
=for HTML <p>
<img src="https://raw.githubusercontent.com/lichtkind/Chart/main/dev/example/manual/direction.png" alt="polar chart">
</p>
The class Chart::Direction creates a diagram based on polar coordinates.
This type of diagram is occasionally referred to as a radial or as a radar
chart, which has a circle as x-axis and its values define an angle.
The y-value in the center is L<min_value|Chart::Manual::Properties/min_value> and
the most outer circle is at L<max_value|Chart::Manual::Properties/max_value>.
In order to reverse that you have to set L<polar|Chart::Manual::Properties/polar> C<'true'>.
In our example we preferred to have a real comparison between arrow lengths
so we artificially put zero as C<min_value> by setting L<include_zero|Chart::Manual::Properties/include_zero>
C<'true'>. The just mentioned arrow style we achieved by deactivating
L<point|Chart::Manual::Properties/point> (drawing small circles) and
turning on L<arrow|Chart::Manual::Properties/arrow>. An additional
C<'true'> L<line|Chart::Manual::Properties/line> would connect the
points (arrow heads) with lines (as well as the first and last).
As in L<\Lines> and L<\Points>: L<pt_size|Chart::Manual::Properties/pt_size>
defines the point size and L<brush_size|Chart::Manual::Properties/brush_size>
the line thickness. Usually the background of each chart (just inside
the coordinate system) is a light gray - here deactivated. Radial
grid lines are drawn every 45 degrees (L<angle_interval|Chart::Manual::Properties/angle_interval>).
As with most chart types, the first data set defines the domain :
the x-values of all following data sets, which then define the associated
y-values (and therefore all sets have to have the same length).
Because we set in this example L<pairs|Chart::Manual::Properties/pairs>
C<'true'>, now every odd numbered data set is the domain for the next set.
But they still all sets have to have the same length.
use Chart::Direction;
my $g = Chart::Direction->new( 500, 500 );
$g->add_dataset( 210, 220, 200, 215, 225, 200 );
$g->add_dataset( 30, 40, 20, 35, 45, 20 );
$g->add_dataset( 30, 40, 20, 35, 45, 20 );
$g->add_dataset( 30, 40, 20, 35, 45, 20 );
$g->add_dataset( 120, 130, 110, 125, 135, 110 );
$g->add_dataset( 30, 40, 20, 35, 45, 20 );
$g->add_dataset( 300, 310, 290, 305, 315, 290 );
$g->add_dataset( 30, 40, 20, 35, 45, 20 );
$g->set(
title => 'Direction Demo',
angle_interval => 45,
precision => 0,
arrow => 'true',
point => 'false',
include_zero => 'true',
legend => 'none',
grey_background => 'false',
pairs => 'true',
);
$g->png("direction.png");
=head2 ErrorBars
=for HTML <p>
<img src="https://raw.githubusercontent.com/lichtkind/Chart/main/dev/example/manual/error.png" alt="error bar chart">
</p>
The class Chart::ErrorBars creates a point chart with error bars, which
are vertical lines, depicting the uncertainty - a range which is possible
for that value. As seen in the example, we need four data sets to define
a series of error bars. The first data set are the x-values of the error
bars, the second the y-values. The third set holds the lenght of the upper
part of the error bar and the fourth set the lower part (distance between
main point and the lower bound of the error bar). The fourth set might be
omitted, when property L<same_error|Chart::Manual::Properties/same_error>
is set C<'true'>. In this case upper and lower part of the error bar have
the same size. Because all this produced only one set of error bars
with one color, there is no need for a legend. That is why it is switched
off by setting property L<legend|Chart::Manual::Properties/legend> to
C<'none'>. The label on the x-axis are painted in the C<'staggered'> style,
so they don't overlap. L<pt_size|Chart::Manual::Properties/pt_size> refers
to the diameter in pixel of the errors bars central point.
L<brush_size|Chart::Manual::Properties/brush_size> is the thickness of the bar.
For better readability C<'both'> L<y_axes|Chart::Manual::Properties/y_axes> were labeled.
use Chart::ErrorBars;
my $g = Chart::ErrorBars->new( 500, 400 );
$g->add_dataset(qw(1 1.1 1.2 1.3 1.4 1.5 1.6 1.7 1.8 1.9 2 2.1 2.2 2.3 2.4 2.5));
$g->add_dataset(qw(1 1.1 1.2 1.1 1.14 1.15 1.26 1.2 1.1 1.19 1.2 1.4 1.6 2.0 2.5 3.1));
$g->add_dataset(qw(0.4 0.1 0.2 0.1 0.14 0.15 0.26 0.27 0.1 0.19 0.2 0.1 0.1 0.2 0.1 0.3));
$g->add_dataset(qw(0.2 0.11 0.12 0.11 0.2 0.3 0.12 0.27 0.11 0.3 0.2 0.2 0.2 0.1 0.1 0.2));
$g->set(
title => 'Error Bars Demo',
legend => 'none',
y_axes => 'both',
x_ticks => 'staggered',
pt_size => 12,
brush_size => 2,
grid_lines => 'true',
colors => {
grid_lines => 'gray70',
misc => 'gray65',
},
);
$g->png("error.png");
=head2 HorizontalBars
=for HTML <p>
<img src="https://raw.githubusercontent.com/lichtkind/Chart/main/dev/example/manual/hbars.png" alt="horizontal bar chart">
</p>
The class Chart::HorizontalBars creates a chart of horizontally oriented bars.
Same rules apply as in L</Bars>, except due negative values in our data sets
here L<min_val|Chart::Manual::Properties/min_val> doesn't have to be set to zero.
And instead of L<y_grid_lines|Chart::Manual::Properties/y_grid_lines>
we activate and color L<x_grid_lines|Chart::Manual::Properties/x_grid_lines>.
Deactivating the grey background of the plot just adds a little friendliness.
use Chart::HorizontalBars;
my $g = Chart::HorizontalBars->new( 600, 600 );
$g->add_dataset( qw/ camel cat dog bear shell/ );
$g->add_dataset( -300, 400, 800, -500, 200 );
$g->add_dataset( 800, -600, 300, 300, 400 );
$g->set(
title => 'Bars !',
x_label => 'Group',
y_label => 'Value',
x_grid_lines => 'true',
precision => 0,
colors => {
x_grid_lines => 'gray70',
misc => 'gray55',
text => 'gray55',
x_label => 'gray40',
y_label => 'gray40',
title => 'gray20',
}
grey_background => 'false',
);
$g->png("hbars.png");
=head2 Lines
=for HTML <p>
<img src="https://raw.githubusercontent.com/lichtkind/Chart/main/dev/example/manual/lines.png" alt="xy chart with lines">
</p>
The class Chart::Lines creates a chart with lines that connect the would
be data points. If you want to make the points more visible,
use L</LinesPoints>. The only special property is L<brush_size|Chart::Manual::Properties/brush_size>,
the thickness of the lines, which was not even utilized in this example.
To make things nicer we put only some softer colors to the horizontal (y)
grid lines and the box and ticks (misc) and placed the legend on the bottom
so that the chart doesn't get sqeezed by it.
use Chart::Lines;
my $g = Chart::Lines->new( 600, 400 );
$g->add_dataset( 'foo', 'bar', 'whee', 'ding', 'bat', 'bit' );
$g->add_dataset( 3.2, 4.34, 9.456, 10.459, 11.24234, 14.0234 );
$g->add_dataset( -1.3, 8.4, 5.34, 3.234, 4.33, 13.09 );
$g->add_dataset( 5, 7, 2, 10, 12, 2.3445 );
$g->set(
title => 'Lines Chart',
legend => 'bottom' ,
y_label => 'y label 1',
precision => 0,
y_grid_lines => 'true',
colors => {
y_label => 'orangepeel',
y_grid_lines => [ 190, 190, 190 ],
misc => [ 100, 100, 100 ],
},
);
$g->png("lines.png");
=head2 LinesPoints
=for HTML <p>
<img src="https://raw.githubusercontent.com/lichtkind/Chart/main/dev/example/manual/linespoints.png" alt="xy chart with connected points">
</p>
The class Chart::LinesPoints creates chart, which is a combination of
L</Points> and L</Lines>: shaped symbols connected by lines. This
requires a combination of the special properties of both chart types:
L<brushStyle|Chart::Manual::Properties/brushStyle> (point shape),
L<pt_size|Chart::Manual::Properties/pt_size> (point diameter) and
L<brush_size|Chart::Manual::Properties/brush_size> (line thickness).
In our example we named both axis via L<x_label|Chart::Manual::Properties/x_label>
and L<y_label|Chart::Manual::Properties/y_label> and set L<xy_plot|Chart::Manual::Properties/xy_plot>
off, which is not really needed, since it is on C<'false'> per default.
This allows you to give the x-axis none numerical, custom tick labels,
which are by accident the numbers 1 .. 17, as the first data row shows.
The purpose of this maneuver is to not have zero as the first column label.
Because the origin of coordinate system is usually in the left lower
corner, we used a trick to flip the y-axis having the smallest values up.
We negated all values in the data, so that 8 is lower than 2, because
-8 is smaller than -2. Than we transformed the y-axis labels with a function,
that negates the value of the original label, erasing the minus sign.
For additional clarity, we put the names of the teams into the legend,
which is per default on the right side. And to make the code more compact,
we packed the first (just labels) and the four real data sets (rows)
together into an array or arrays and gave it as second argument directly
to the drawing method.
use Chart::LinesPoints;
my $g = Chart::LinesPoints->new( 600, 300 );
$g->set(
title => 'Soccer Season 2002',
legend_labels => ['NY Soccer Club', 'Denver Tigers',
'Houston Spacecats', 'Washington Presidents'],
y_label => 'position in the table',
x_label => 'day of play',
grid_lines => 'true',
f_y_tick => sub { - $_[0] },
# xy_plot => 'true',
integer_ticks_only => 'true',
colors => {
grid_lines => 'gray70',
},
);
$g->png("linespoints.png", [
[qw(1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17)],
[qw(-7 -5 -6 -8 -9 -7 -5 -4 -3 -2 -4 -6 -3 -5 -3 -4 -6)],
[qw(-1 -1 -1 -1 -2 -2 -3 -3 -4 -4 -6 -3 -2 -2 -2 -1 -1)],
[qw(-4 -4 -3 -2 -1 -1 -1 -2 -1 -1 -3 -2 -4 -3 -4 -2 -2)],
[qw(-6 -3 -2 -3 -3 -3 -2 -1 -2 -3 -1 -1 -1 -1 -1 -3 -3)],
]);
=head2 Mountain
=for HTML <p>
<img src="https://raw.githubusercontent.com/lichtkind/Chart/main/dev/example/manual/mountain.png" alt="mountain chart">
</p>
The class Chart::Mountain creates a mountain chart, which is a line chart
(see L</Lines>), where the area under the curve, right to the curve below
is filled with the color of the data set. In the following example we use
custom colors in hex notation (as supported by Chart::Color) which are
getting mapped onto the colors settings of
L<dataset0|Chart::Manual::Properties/colors-datasetx> .. dataset4.
As always, the first data set (row in the data table) holds the domain or
x-axis labels. Another specialty of mountain charts are patterns (not provided !),
to fill the area with. We load them via GD and give them over to the
C<'patterns'> property. Patterns are small images with one color and the
second being transparent.
use Chart::Mountain;
my @data = (
["1st", "2nd", "3rd", "4th", "5th", "6th", "7th", "8th", "9th" ],
[ 3, 7, 8, 2, 4 , 8.5, 2, 5, 9],
[ 4, 2, 5, 6, 3 , 2.5, 3, 3, 4],
[ 7, 3, 2, 8, 8.5, 2 , 9, 4, 5],
);
my @hex_colors = ('#0099FF', '#00CC00', '#EEAA00', '#FF0099','#3333FF');
my $PNG;
my @patterns = map {
open( $PNG, '<', "./patterns/PATTERN$_.PNG" ) or die "Can't load pattern $_";
GD::Image->newFromPng( $PNG );
} 0 .. 4;
my $g = new Chart::Mountain( 500, 300);
$g->set(
title => 'Mountain Chart with Patterns',
x_label => 'Lengths',
y_label => 'Height',
grid_lines => 'true',
patterns => \@patterns,
precision => 1,
colors => {
grid_lines => 'gray70',
misc => 'gray55',
map { ( "dataset$_" => $hex_colors[$_] ) } 0 .. $#hex_colors,
},
);
$g->png( 'mountain.png', \@data );
=head2 Pareto
=for HTML <p>
<img src="https://raw.githubusercontent.com/lichtkind/Chart/main/dev/example/manual/pareto.png" alt="pareto chart">
</p>
The class Chart::Pareto creates a combination of a L</Bars> and a L</Lines>
chart. The bars display absolute values of the data set (Pareto accepts
only one), while the line represent the accumulation (sum of all values
from the start on the left up to this value). For a better orientation
the absolute values should be sorted. In case your data set is not already,
change the property L<sort|Chart::Manual::Properties/sort> to C<'true'>.
(Note that the days of the week are not in chronological order,
but in the order of decreasing sale amounts.) The first given data set
is like in most cases the domain (x-axis labels). So the color of the first
data set containing numbers has the color of
L<dataset0|Chart::Manual::Properties/colors-datasetx> and the accumulation
gets the color of dataset1 (which are per default also red and green,
but in reverse order). We choose a Pantone Report designer red, which
sticks out but is not too shrill.
For better optics we set L<spaced_bars|Chart::Manual::Properties/spaced_bars>
off, so that the bars touch each other and give a nice counterweight to
the red color of the line. It's also a bit nicer, when the red labels
above the red line don't stick out the chart, so we increased the
L<max_val|Chart::Manual::Properties/max_val> from 5180 to 5500. Finally
to prevent the y-axis from overcrowding, we set labels (and y_grid_lines)
only every 250 by setting L<skip_int_ticks|Chart::Manual::Properties/skip_int_ticks>
and activating L<integer_ticks_only|Chart::Manual::Properties/integer_ticks_only>.
use Chart::Pareto;
my $g = Chart::Pareto->new( 450, 400 );
$g->add_dataset( 'Mo', 'Tue', 'We', 'Th', 'Fr', 'Sa', 'Su' );
$g->add_dataset( 2500, 1000, 250, 700, 100, 610, 20 );
$g->set(
title => 'Sold Tickets for Beethovens 9th',
y_label => 'Sold Tickets',
x_label => '! sold out in the first week !',
sort => 'true',
max_val => 5500,
integer_ticks_only => 'true',
skip_int_ticks => 250,
y_grid_lines => 'true',
spaced_bars => 'false',
legend => 'none',
colors => {
title => 'darkblue',
dataset0 => 'green',
dataset1 => 'aurorared',
x_label => 'aurorared',
y_grid_lines => 'white',
},
);
$g->png("pareto.png");
=head2 Pie
=for HTML <p>
<img src="https://raw.githubusercontent.com/lichtkind/Chart/main/dev/example/manual/pie.png" alt="pie chart">
</p>
The class Chart::Pie creates a pie or ring chart. The first added data
set must contain the labels and the second set the values. Our example
displays a ring chart with a thickness of 35% (of the radius). If the
L<ring|Chart::Manual::Properties/ring> property is omitted, the chart form
falls back to regular pie. Every ring slice is labeled with the stated label,
plus the percentage of its value, as defined with the property
L<label_values|Chart::Manual::Properties/label_values>. Connecting lines
between label and slice are drawn because L<legend_lines|Chart::Manual::Properties/legend_lines>
is set to C<'true'>. The actual legend is placed on the bottom, in order
to leave the ring as large as possible. The legend again shows the
association between color and data point and its value because
L<legend_label_values|Chart::Manual::Properties/legend_label_values>
is set to C<'values'>. Unlike other chart types, where one data set is
correlated with a color, here every slice has to have its own color.
Thats why the first data point has the color of L<dataset0|Chart::Manual::Properties/colors-datasetx>
the second of dataset1 and so forth. In most cases the default colors
are good enough, unless you have special meanings in mind. Please also
note the multi line (row) title text.
use Chart::Pie;
my $g = Chart::Pie->new( 500, 450 );
$g->add_dataset( qw/eins zwei drei vier fuenf sechs sieben acht neun zehn/ );
$g->add_dataset( 120, 50, 100, 80, 40, 45, 150, 60, 110, 50 );
$g->set( 'title' => 'Pie\nDemo Chart',
'legend' => 'bottom',
'legend_label_values' => 'value',
'label_values' => 'percent',
'legend_lines' => 'true',
'ring' => 0.35,
);
$g->png("pie.png");
=head2 Points
=for HTML <p>
<img src="https://raw.githubusercontent.com/lichtkind/Chart/main/dev/example/manual/points.png" alt="xy chart with points">
<img src="https://raw.githubusercontent.com/lichtkind/Chart/main/dev/example/test/points_5.png" alt="point styles demo">
</p>
The class Chart::Points creates a xy-chart (also called scattergram),
where the individual data points are marked with a symbol.
The shape of the symbol is selected by the property L<brushStyle|Chart::Manual::Properties/brushStyle>,
which was not utilized in this example, in order to use the default shape:
a circle of a diameter set by L<pt_size|Chart::Manual::Properties/pt_size>.
All shapes can be seen in the demo above, right.
(If you want in addition lines, connecting the points, check L</LinesPoints>.)
The first data set comprises the domain set, displayed on the x-axis.
L<precision|Chart::Manual::Properties/precision> set to zero cuts the
decimals on the y-axis labels and keeps it clean. The method C<add_pt>
appends to every data set another value, adding another column to the chart.
L<png_border|Chart::Manual::Properties/png_border> does just adds frame
of 10 pixel width around the entire image. They middle gray grid lines
are just easy for the eyes.
use Chart::Points;
my $g = Chart::Points->new();
$g->add_dataset( 'foo', 'bar', 'blank' );
$g->add_dataset( 3, 4, 9 );
$g->add_dataset( 8, 6, 0 );
$g->add_dataset( 5, 7, 2 );
$g->add_pt( 'dat', 1, 5, 7 );
$g->set(
title => 'Points Chart',
pt_size => 18,
# brushStyle => 'Star',
precision => 0,
grid_lines => 'true',
png_border => 10,
colors => {
grid_lines => 'gray70',
},
);
$g->png("points.png");
=head2 Split
=for HTML <p>
<img src="https://raw.githubusercontent.com/lichtkind/Chart/main/dev/example/manual/split.png" alt="multi chart">
</p>
The class Chart::Split creates a L</Lines> chart where both x and y axes
are assumed to be numeric. Split charts are mainly intended for cases
where many data points are spread over a wide x range while at the
same time the y range is limited. Typical examples are weather or
seismic data. The x axis will be split into several intervals of the
same length (specified with the mandatory option L<interval|Chart::Manual::Properties/interval>
and starting at L<start|Chart::Manual::Properties/start>). Chart::Split will
draw only positive x coordinates. The y axis will not be labelled with
the y values. Rather, the axis will show only the sequence numbers
of the intervals.
use Chart::Split;
my $g = Chart::Split->new( 500, 500 );
my @domain = 1 .. 4000;
my @rnd = map { srand( time() / $_ * 50 ); rand(10) } @domain, 4001;
my @diff = map { abs $rnd[$_-1] - $rnd[$_] } @domain;
pop @rnd;
$g->add_dataset(@domain);
$g->add_dataset(@rnd);
$g->add_dataset(@diff);
$g->set(
title => "Random Numbers Test",
x_label => "4000 Random Numbers",
start => 0,
interval => 400,
brush_size => 1,
interval_ticks => 0,
legend => 'bottom',
legend_labels => ['random numbers', 'difference' ],
colors => {
title => 'darkblue',
text => 'gray45',
misc => 'gray45',
},
);
$g->png("split.png");
=head2 StackedBars
=for HTML <p>
<img src="https://raw.githubusercontent.com/lichtkind/Chart/main/dev/example/manual/stackedbars.png" alt="stacked bar chart">
</p>
The class Chart::StackedBars is a variant of L</Bars> that stacks
bars belonging to one x-value on top of each other, instead of putting
them beside each other. Data sets 0..n are ordered from the bottom up.
They are in most cases more intuitive than L</Pie> charts, because its
easier to intuit linear than quadratic ratios. As in the Bars example we
activated horizontal grid lines, which were subtle colored. To surpress
decimals on the y-axis L<precision|Chart::Manual::Properties/precision> was turned down.
And as in most cases - the first data set is the domain, which will be
drawn as x-axis labels.
use Chart::StackedBars;
my $g = Chart::StackedBars->new( 600, 400 );
$g->add_dataset( 'camel', 'dromedar', 'llama', 'vicuna');
$g->add_dataset( 3, 4, 9, 10, );
$g->add_dataset( 8, 6, 1, 12, );
$g->add_dataset( 5, 7, 2, 13, );
$g->set(
title => 'Stacked Bars',
legend => 'left',
precision => 0,
y_grid_lines => 'true',
grey_background => 'false',
colors => {
grid_lines => 'gray80',
misc => 'gray55',
text => 'gray55',
x_label => 'gray40',
y_label => 'gray40',
title => 'gray20',
}
);
$g->png("stackedbars.png");
=head1 COPYRIGHT & LICENSE
Copyright 2022 David Bonner, Herbert Breunung.
This program is free software; you can redistribute it and/or modify it
under same terms as Perl itself.
=head1 AUTHOR
David Bonner,
Herbert Breunung, <lichtkind@cpan.org>
=cut
|