{
    "mode": "perldoc",
    "parameter": "Chart::Manual::Types",
    "section": "",
    "url": "https://www.chedong.com/phpMan.php/perldoc/Chart%3A%3AManual%3A%3ATypes/json",
    "generated": "2026-10-08T03:21:22Z",
    "sections": {
        "NAME": {
            "content": "Chart::Manual::Types - all chart types by example\n",
            "subsections": []
        },
        "OVERVIEW": {
            "content": "This page illustrates all supported chart types, describes their special abilities and\nprogramming needs. Detailled information is linked whenever possible.\n\nCurrently available are xycharts with points, lines, mountains, bar charts, stacked bars, error\nbars, pie and ring charts with split and polar coordinate systems. Also composite charts are\npossible.\n\nGenerally, each chart type here is implementd by a class: Chart::* (name), which inherits most\nof its methods from Chart::Base. Every constructor takes two arguments, which are width and\nheight of the later generated image.\n",
            "subsections": [
                {
                    "name": "Bars",
                    "content": "The class Chart::Bars creates a chart made up of a series of vertical bars. The length of each\nbar depicts one value of your second data set. The first data set however, defines the domain.\nIn this example the first value of the first (domain) data set is 'camel'. So the first value of\nthe second set (300) is positioned above the first tick on the x-axis labeled 'camel'. Right\nbeside it is a differently colored bar, depticting the first value of the third data set (800).\nSince the option spacedbars is set to 'true' on default, both bars are separated from the next\ngroup of bars. In this example it also makes also sense to activate the horizontal ygridlines\nand give them a subtle color. Further important was it to set the property minval to zero, so\nthat the bars could be seen in full length and not from the min value of the data sets (300) on\nupwards. precision set to zero just drops the decimals on the tick label so the chart looks a\nlittle cleaner. All the the other color set serv the same purpose.\n\nuse Chart::Bars;\n\nmy $g = Chart::Bars->new( 500, 300 );\n$g->adddataset( qw/ camel cat dog bear shell/ );\n$g->adddataset( 300, 400, 800, 500, 900 );\n$g->adddataset( 800, 600, 300, 300, 400 );\n\n$g->set(\ntitle         => 'Bars !',\nxlabel       => 'Group',\nylabel       => 'Value',\nygridlines  => 'true',\ncolors => {\nygridlines => 'gray70',\nmisc         => 'gray55',\ntext         => 'gray55',\nxlabel      => 'gray40',\nylabel      => 'gray40',\ntitle        => 'gray20',\n},\nminval       =>  0,\nprecision     =>  0,\n# spacedbars   => 'false',\n);\n$g->png(\"bars.png\");\n"
                },
                {
                    "name": "Composite",
                    "content": "The class Chart::Composite creates a two component chart with two types of charts which are\nlayered one above each other. Just set the option composite info. For example, you can create a\ntwo component chart with bars and lines. A composite chart does not make sense with all\ncombinations of chart types, but it works pretty good with Lines, Points, LinesPoints and Bars.\nNote that two similar chart types may come into visual conflict. Chart::Composite can do only\ncomposite charts made up of two components.\n\nIn this example are the data sets one and two displayed as \"Bars\" and the next two als\n\"LinesPoints\" as set by the property compositeinfo. Please read these sections too. Otherwise\nwe only colored the last data set for better contrast und cut the decimals from the axis labels\nvia precision.\n\nuse Chart::Composite;\n\nmy $g = Chart::Composite->new( );\n$g->adddataset( 1,   2,   3 );\n$g->adddataset( 10,  20,  30 );\n$g->adddataset( 15,  25,  32 );\n$g->adddataset( 7,   24,  23 );\n$g->adddataset( 5.1, 7.5, 9.9 );\n$g->set(\ntitle          => 'Composite Chart',\ncompositeinfo => [ [ 'Bars',        [ 1, 2 ] ],\n[ 'LinesPoints', [ 3, 4 ] ]  ],\nincludezero   => 'true',\nprecision      => 0,\ncolors  => {\ndataset3     => 'darkorange',\n}\n);\n$g->png(\"composite.png\");\n"
                },
                {
                    "name": "Direction",
                    "content": "The class Chart::Direction creates a diagram based on polar coordinates. This type of diagram is\noccasionally referred to as a radial or as a radar chart, which has a circle as x-axis and its\nvalues define an angle. The y-value in the center is minvalue and the most outer circle is at\nmaxvalue. In order to reverse that you have to set polar 'true'. In our example we preferred to\nhave a real comparison between arrow lengths so we artificially put zero as \"minvalue\" by\nsetting includezero 'true'. The just mentioned arrow style we achieved by deactivating point\n(drawing small circles) and turning on arrow. An additional 'true' line would connect the points\n(arrow heads) with lines (as well as the first and last). As in \\Lines and \\Points: ptsize\ndefines the point size and brushsize the line thickness. Usually the background of each chart\n(just inside the coordinate system) is a light gray - here deactivated. Radial grid lines are\ndrawn every 45 degrees (angleinterval).\n\nAs with most chart types, the first data set defines the domain : the x-values of all following\ndata sets, which then define the associated y-values (and therefore all sets have to have the\nsame length). Because we set in this example pairs 'true', now every odd numbered data set is\nthe domain for the next set. But they still all sets have to have the same length.\n\nuse Chart::Direction;\n\nmy $g = Chart::Direction->new( 500, 500 );\n\n$g->adddataset( 210, 220, 200, 215, 225, 200 );\n$g->adddataset(  30,  40,  20,  35,  45,  20 );\n\n$g->adddataset( 30, 40, 20, 35, 45, 20 );\n$g->adddataset( 30, 40, 20, 35, 45, 20 );\n\n$g->adddataset( 120, 130, 110, 125, 135, 110 );\n$g->adddataset(  30,  40,  20,  35,  45,  20 );\n\n$g->adddataset( 300, 310, 290, 305, 315, 290 );\n$g->adddataset(  30,  40,  20,  35,  45,  20 );\n\n$g->set(\ntitle           => 'Direction Demo',\nangleinterval  =>  45,\nprecision       =>   0,\narrow           => 'true',\npoint           => 'false',\nincludezero    => 'true',\nlegend          => 'none',\ngreybackground => 'false',\npairs           => 'true',\n);\n$g->png(\"direction.png\");\n"
                },
                {
                    "name": "ErrorBars",
                    "content": "The class Chart::ErrorBars creates a point chart with error bars, which are vertical lines,\ndepicting the uncertainty - a range which is possible for that value. As seen in the example, we\nneed four data sets to define a series of error bars. The first data set are the x-values of the\nerror bars, the second the y-values. The third set holds the lenght of the upper part of the\nerror bar and the fourth set the lower part (distance between main point and the lower bound of\nthe error bar). The fourth set might be omitted, when property sameerror is set 'true'. In this\ncase upper and lower part of the error bar have the same size. Because all this produced only\none set of error bars with one color, there is no need for a legend. That is why it is switched\noff by setting property legend to 'none'. The label on the x-axis are painted in the 'staggered'\nstyle, so they don't overlap. ptsize refers to the diameter in pixel of the errors bars central\npoint. brushsize is the thickness of the bar. For better readability 'both' yaxes were\nlabeled.\n\nuse Chart::ErrorBars;\n\nmy $g = Chart::ErrorBars->new( 500, 400 );\n$g->adddataset(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));\n$g->adddataset(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));\n$g->adddataset(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));\n$g->adddataset(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));\n$g->set(\ntitle          => 'Error Bars Demo',\nlegend         => 'none',\nyaxes         => 'both',\nxticks        => 'staggered',\nptsize        =>  12,\nbrushsize     =>   2,\ngridlines     => 'true',\ncolors => {\ngridlines   => 'gray70',\nmisc         => 'gray65',\n},\n);\n$g->png(\"error.png\");\n"
                },
                {
                    "name": "HorizontalBars",
                    "content": "The class Chart::HorizontalBars creates a chart of horizontally oriented bars. Same rules apply\nas in \"Bars\", except due negative values in our data sets here minval doesn't have to be set to\nzero. And instead of ygridlines we activate and color xgridlines. Deactivating the grey\nbackground of the plot just adds a little friendliness.\n\nuse Chart::HorizontalBars;\n\nmy $g = Chart::HorizontalBars->new( 600, 600 );\n$g->adddataset( qw/ camel cat dog bear shell/ );\n$g->adddataset( -300,  400, 800, -500, 200 );\n$g->adddataset(  800, -600, 300,  300, 400 );\n$g->set(\ntitle         => 'Bars !',\nxlabel       => 'Group',\nylabel       => 'Value',\nxgridlines  => 'true',\nprecision     =>  0,\ncolors => {\nxgridlines => 'gray70',\nmisc         => 'gray55',\ntext         => 'gray55',\nxlabel      => 'gray40',\nylabel      => 'gray40',\ntitle        => 'gray20',\n}\ngreybackground  => 'false',\n);\n$g->png(\"hbars.png\");\n"
                },
                {
                    "name": "Lines",
                    "content": "The class Chart::Lines creates a chart with lines that connect the would be data points. If you\nwant to make the points more visible, use \"LinesPoints\". The only special property is\nbrushsize, the thickness of the lines, which was not even utilized in this example. To make\nthings nicer we put only some softer colors to the horizontal (y) grid lines and the box and\nticks (misc) and placed the legend on the bottom so that the chart doesn't get sqeezed by it.\n\nuse Chart::Lines;\n\nmy $g = Chart::Lines->new( 600, 400 );\n$g->adddataset( 'foo', 'bar', 'whee', 'ding', 'bat',    'bit' );\n$g->adddataset(  3.2,  4.34, 9.456,  10.459, 11.24234, 14.0234 );\n$g->adddataset( -1.3,   8.4,  5.34,   3.234,     4.33, 13.09 );\n$g->adddataset(    5,     7,     2,      10,       12,  2.3445 );\n$g->set(\ntitle        => 'Lines Chart',\nlegend       => 'bottom' ,\nylabel      => 'y label 1',\nprecision    =>  0,\nygridlines => 'true',\ncolors       => {\nylabel      => 'orangepeel',\nygridlines => [ 190, 190, 190 ],\nmisc         => [ 100, 100, 100 ],\n},\n);\n$g->png(\"lines.png\");\n"
                },
                {
                    "name": "LinesPoints",
                    "content": "The class Chart::LinesPoints creates chart, which is a combination of \"Points\" and \"Lines\":\nshaped symbols connected by lines. This requires a combination of the special properties of both\nchart types: brushStyle (point shape), ptsize (point diameter) and brushsize (line thickness).\n\nIn our example we named both axis via xlabel and ylabel and set xyplot off, which is not\nreally needed, since it is on 'false' per default. This allows you to give the x-axis none\nnumerical, custom tick labels, which are by accident the numbers 1 .. 17, as the first data row\nshows. The purpose of this maneuver is to not have zero as the first column label.\n\nBecause the origin of coordinate system is usually in the left lower corner, we used a trick to\nflip the y-axis having the smallest values up. We negated all values in the data, so that 8 is\nlower than 2, because -8 is smaller than -2. Than we transformed the y-axis labels with a\nfunction, that negates the value of the original label, erasing the minus sign.\n\nFor additional clarity, we put the names of the teams into the legend, which is per default on\nthe right side. And to make the code more compact, we packed the first (just labels) and the\nfour real data sets (rows) together into an array or arrays and gave it as second argument\ndirectly to the drawing method.\n\nuse Chart::LinesPoints;\n\nmy $g = Chart::LinesPoints->new( 600, 300 );\n$g->set(\ntitle              => 'Soccer Season 2002',\nlegendlabels      => ['NY Soccer Club', 'Denver Tigers',\n'Houston Spacecats', 'Washington Presidents'],\nylabel            => 'position in the table',\nxlabel            => 'day of play',\ngridlines         => 'true',\nfytick           =>  sub { - $[0] },\n# xyplot            => 'true',\nintegerticksonly => 'true',\ncolors             => {\ngridlines     => 'gray70',\n},\n);\n$g->png(\"linespoints.png\", [\n[qw(1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17)],\n[qw(-7 -5 -6 -8 -9 -7 -5 -4 -3 -2 -4 -6 -3 -5 -3 -4 -6)],\n[qw(-1 -1 -1 -1 -2 -2 -3 -3 -4 -4 -6 -3 -2 -2 -2 -1 -1)],\n[qw(-4 -4 -3 -2 -1 -1 -1 -2 -1 -1 -3 -2 -4 -3 -4 -2 -2)],\n[qw(-6 -3 -2 -3 -3 -3 -2 -1 -2 -3 -1 -1 -1 -1 -1 -3 -3)],\n]);\n"
                },
                {
                    "name": "Mountain",
                    "content": "The class Chart::Mountain creates a mountain chart, which is a line chart (see \"Lines\"), where\nthe area under the curve, right to the curve below is filled with the color of the data set. In\nthe following example we use custom colors in hex notation (as supported by Chart::Color) which\nare getting mapped onto the colors settings of dataset0 .. dataset4. As always, the first data\nset (row in the data table) holds the domain or x-axis labels. Another specialty of mountain\ncharts are patterns (not provided !), to fill the area with. We load them via GD and give them\nover to the 'patterns' property. Patterns are small images with one color and the second being\ntransparent.\n\nuse Chart::Mountain;\n\nmy @data = (\n[\"1st\", \"2nd\", \"3rd\", \"4th\", \"5th\", \"6th\", \"7th\", \"8th\", \"9th\" ],\n[ 3, 7, 8, 2, 4  , 8.5, 2, 5, 9],\n[ 4, 2, 5, 6, 3  , 2.5, 3, 3, 4],\n[ 7, 3, 2, 8, 8.5, 2  , 9, 4, 5],\n);\nmy @hexcolors = ('#0099FF', '#00CC00', '#EEAA00', '#FF0099','#3333FF');\nmy $PNG;\nmy @patterns = map {\nopen( $PNG, '<', \"./patterns/PATTERN$.PNG\" ) or die \"Can't load pattern $\";\nGD::Image->newFromPng( $PNG );\n} 0 .. 4;\n\nmy $g = new Chart::Mountain( 500, 300);\n$g->set(\ntitle      => 'Mountain Chart with Patterns',\nxlabel    => 'Lengths',\nylabel    => 'Height',\ngridlines => 'true',\npatterns   => \\@patterns,\nprecision  => 1,\ncolors => {\ngridlines => 'gray70',\nmisc       => 'gray55',\nmap { ( \"dataset$\" => $hexcolors[$] ) } 0 .. $#hexcolors,\n},\n);\n$g->png( 'mountain.png', \\@data );\n"
                },
                {
                    "name": "Pareto",
                    "content": "The class Chart::Pareto creates a combination of a \"Bars\" and a \"Lines\" chart. The bars display\nabsolute values of the data set (Pareto accepts only one), while the line represent the\naccumulation (sum of all values from the start on the left up to this value). For a better\norientation the absolute values should be sorted. In case your data set is not already, change\nthe property sort to 'true'. (Note that the days of the week are not in chronological order, but\nin the order of decreasing sale amounts.) The first given data set is like in most cases the\ndomain (x-axis labels). So the color of the first data set containing numbers has the color of\ndataset0 and the accumulation gets the color of dataset1 (which are per default also red and\ngreen, but in reverse order). We choose a Pantone Report designer red, which sticks out but is\nnot too shrill.\n\nFor better optics we set spacedbars off, so that the bars touch each other and give a nice\ncounterweight to the red color of the line. It's also a bit nicer, when the red labels above the\nred line don't stick out the chart, so we increased the maxval from 5180 to 5500. Finally to\nprevent the y-axis from overcrowding, we set labels (and ygridlines) only every 250 by setting\nskipintticks and activating integerticksonly.\n\nuse Chart::Pareto;\n\nmy $g = Chart::Pareto->new( 450, 400 );\n$g->adddataset( 'Mo', 'Tue', 'We', 'Th', 'Fr', 'Sa', 'Su' );\n$g->adddataset( 2500, 1000,  250,  700,  100,  610,  20 );\n$g->set(\ntitle              => 'Sold Tickets for Beethovens 9th',\nylabel            => 'Sold Tickets',\nxlabel            => '! sold out in the first week !',\nsort               => 'true',\nmaxval            => 5500,\nintegerticksonly => 'true',\nskipintticks     => 250,\nygridlines       => 'true',\nspacedbars        => 'false',\nlegend             => 'none',\ncolors  => {\ntitle        => 'darkblue',\ndataset0     => 'green',\ndataset1     => 'aurorared',\nxlabel      => 'aurorared',\nygridlines => 'white',\n},\n);\n$g->png(\"pareto.png\");\n"
                },
                {
                    "name": "Pie",
                    "content": "The class Chart::Pie creates a pie or ring chart. The first added data set must contain the\nlabels and the second set the values. Our example displays a ring chart with a thickness of 35%\n(of the radius). If the ring property is omitted, the chart form falls back to regular pie.\nEvery ring slice is labeled with the stated label, plus the percentage of its value, as defined\nwith the property labelvalues. Connecting lines between label and slice are drawn because\nlegendlines is set to 'true'. The actual legend is placed on the bottom, in order to leave the\nring as large as possible. The legend again shows the association between color and data point\nand its value because legendlabelvalues is set to 'values'. Unlike other chart types, where\none data set is correlated with a color, here every slice has to have its own color. Thats why\nthe first data point has the color of dataset0 the second of dataset1 and so forth. In most\ncases the default colors are good enough, unless you have special meanings in mind. Please also\nnote the multi line (row) title text.\n\nuse Chart::Pie;\n\nmy $g = Chart::Pie->new( 500, 450 );\n$g->adddataset( qw/eins zwei drei vier fuenf sechs sieben acht neun zehn/ );\n$g->adddataset( 120, 50, 100, 80, 40, 45, 150, 60, 110, 50 );\n$g->set( 'title'               => 'Pie\\nDemo Chart',\n'legend'              => 'bottom',\n'legendlabelvalues' => 'value',\n'labelvalues'        => 'percent',\n'legendlines'        => 'true',\n'ring'                => 0.35,\n);\n$g->png(\"pie.png\");\n"
                },
                {
                    "name": "Points",
                    "content": "The class Chart::Points creates a xy-chart (also called scattergram), where the individual data\npoints are marked with a symbol. The shape of the symbol is selected by the property brushStyle,\nwhich was not utilized in this example, in order to use the default shape: a circle of a\ndiameter set by ptsize. All shapes can be seen in the demo above, right. (If you want in\naddition lines, connecting the points, check \"LinesPoints\".)\n\nThe first data set comprises the domain set, displayed on the x-axis. precision set to zero cuts\nthe decimals on the y-axis labels and keeps it clean. The method \"addpt\" appends to every data\nset another value, adding another column to the chart. pngborder does just adds frame of 10\npixel width around the entire image. They middle gray grid lines are just easy for the eyes.\n\nuse Chart::Points;\n\nmy $g = Chart::Points->new();\n$g->adddataset( 'foo', 'bar', 'blank' );\n$g->adddataset(  3,  4,  9 );\n$g->adddataset(  8,  6,  0 );\n$g->adddataset(  5,  7,  2 );\n$g->addpt( 'dat', 1, 5,  7 );\n$g->set(\ntitle        => 'Points Chart',\nptsize      => 18,\n# brushStyle   => 'Star',\nprecision    =>  0,\ngridlines   => 'true',\npngborder   => 10,\ncolors => {\ngridlines => 'gray70',\n\n},\n);\n$g->png(\"points.png\");\n"
                },
                {
                    "name": "Split",
                    "content": "The class Chart::Split creates a \"Lines\" chart where both x and y axes are assumed to be\nnumeric. Split charts are mainly intended for cases where many data points are spread over a\nwide x range while at the same time the y range is limited. Typical examples are weather or\nseismic data. The x axis will be split into several intervals of the same length (specified with\nthe mandatory option interval and starting at start). Chart::Split will draw only positive x\ncoordinates. The y axis will not be labelled with the y values. Rather, the axis will show only\nthe sequence numbers of the intervals.\n\nuse Chart::Split;\n\nmy $g = Chart::Split->new( 500, 500 );\n\nmy @domain = 1 .. 4000;\nmy @rnd    = map { srand( time() / $ * 50 ); rand(10) } @domain, 4001;\nmy @diff   = map { abs $rnd[$-1] - $rnd[$] } @domain;\npop @rnd;\n\n$g->adddataset(@domain);\n$g->adddataset(@rnd);\n$g->adddataset(@diff);\n$g->set(\ntitle          => \"Random Numbers Test\",\nxlabel        => \"4000 Random Numbers\",\nstart          => 0,\ninterval       => 400,\nbrushsize     => 1,\nintervalticks => 0,\nlegend         => 'bottom',\nlegendlabels  => ['random numbers', 'difference' ],\ncolors => {\ntitle => 'darkblue',\ntext  => 'gray45',\nmisc  => 'gray45',\n},\n);\n$g->png(\"split.png\");\n"
                },
                {
                    "name": "StackedBars",
                    "content": "The class Chart::StackedBars is a variant of \"Bars\" that stacks bars belonging to one x-value on\ntop of each other, instead of putting them beside each other. Data sets 0..n are ordered from\nthe bottom up. They are in most cases more intuitive than \"Pie\" charts, because its easier to\nintuit linear than quadratic ratios. As in the Bars example we activated horizontal grid lines,\nwhich were subtle colored. To surpress decimals on the y-axis precision was turned down. And as\nin most cases - the first data set is the domain, which will be drawn as x-axis labels.\n\nuse Chart::StackedBars;\n\nmy $g = Chart::StackedBars->new( 600, 400 );\n$g->adddataset( 'camel', 'dromedar', 'llama', 'vicuna');\n$g->adddataset( 3, 4,  9,  10,  );\n$g->adddataset( 8, 6,  1,  12,  );\n$g->adddataset( 5, 7,  2,  13,  );\n$g->set(\ntitle             => 'Stacked Bars',\nlegend            => 'left',\nprecision         =>  0,\nygridlines      => 'true',\ngreybackground   => 'false',\ncolors => {\ngridlines   => 'gray80',\nmisc         => 'gray55',\ntext         => 'gray55',\nxlabel      => 'gray40',\nylabel      => 'gray40',\ntitle        => 'gray20',\n}\n);\n$g->png(\"stackedbars.png\");\n\nCOPYRIGHT & LICENSE\nCopyright 2022 David Bonner, Herbert Breunung.\n\nThis program is free software; you can redistribute it and/or modify it under same terms as Perl\nitself.\n"
                }
            ]
        },
        "AUTHOR": {
            "content": "David Bonner,\n\nHerbert Breunung, <lichtkind@cpan.org>\n",
            "subsections": []
        }
    },
    "summary": "Chart::Manual::Types - all chart types by example",
    "flags": [],
    "examples": [],
    "see_also": []
}