Column Chart
Column Chart
Overview
Chart building
o Single-Series column chart
o Multi-Series column chart
o Multi-Series column chart grouped by series
o 3D column chart
o 3D column chart clustered by Z Axis
Axes management
o Positioning
o Inversion
o Minimum and Maximum values control
Padding between columns and column groups
Using styles
o Simple style sample
o Application of different styles to chart elements
o Predefined Styles
Working with data labels and tooltips
Using markers
Working with colors and color palettes
o Setting colors to the elements
o Color palettes
Working with hatch fills and hatch palettes
o Setting hatch fills to the elements
o Hatch palettes
Overview
A column chart, also known as a bar chart, is a chart with rectangular bars of lengths usually proportional to the
magnitudes or frequencies of what they represent. The bars can be horizontally or vertically oriented. The column
chart is vertically oriented bars. If you want to build horizontally oriented bar charts, please go to: Bar Chart Help
section.
Column charts are useful for showing data changes over a period of time or for illustrating comparisons among
items. In column charts, categories are typically organized along the horizontal axis and values along the vertical
axis.
Chart building
Depending on data model and the visualization purpose the column chart may contain single series or multi series.
AnyChart solution allows to build both 2D (two-dimensional) and 3D (three-dimensional) column charts.
Let's look at the single-series column chart created using the following data - sales of several managers in one
quarter:
Name Sales
John $10000
Jake $12000
Peter $18000
James $11000
Mary $9000
Now we need to convert this data table into XML, this format will be accepted by AnyChart. In terms of AnyChart
data model we have one series of data (Sales) with categories that hold managers names. Each point in series
represents one manager and his/her sales. Converted XML Data looks like:
XML Syntax
XML Code
01 <data>
02 <series name="Sales" type="Bar">
03 <point name="John" y="10000" />
04 <point name="Jake" y="12000" />
05 <point name="Peter" y="18000" />
06 <point name="James" y="11000" />
07 <point name="Mary" y="9000" />
08 </series>
09 </data>
As you can see, we've created one <series> node, specified its type="Bar", added several <point> nodes and
set xattribute that defines column category and y attribute that defines column value.
To compare two or more data rows you have to use multi-series column charts as it is shown in the sample below.
Let's compare the First quarter sales with the Second quarter sales:
As we do in single series column sample above we need to convert this table into XML, the only difference between
these two samples is the fact that now we have two series of data - one series for each quarter, and we give proper
names to each series:
XML Syntax
XML Code
01 <data>
02 <series name="Quarter
1">
03 <point name="John" y="10000" />
04 <point name="Jake" y="12000" />
05 <point name="Peter" y="18000" />
06 <point name="James" y="11000" />
07 <point name="Mary" y="9000" />
08 </series>
09 <series name="Quarter
2">
10 <point name="John" y="12000" />
11 <point name="Jake" y="15000" />
12 <point name="Peter" y="16000" />
13 <point name="James" y="13000" />
14 <point name="Mary" y="19000" />
15 </series>
16 </data>
As we now have multi-series chart we don't want to set type for each series individually (there can be much more
than two series in multi-series chart), so we add <data_plot_settings default_series_type="Bar"/> node
to <chart>. Now all series in chart will be of Bar type by default.
Sometimes it is useful to visualize comparison in a different way - group columns by series. In our sample it means
that we want to compare the sales of all the managers in each quarter, not each manager's sales in different
quarters. You don't have to reformat your data to do this - all you need to do is to switch plot_type attribute to
"CategorizedBySeriesVertical". Look at the resulting chart below:
It is very easy to display the data from the sample above in 3D mode - just set enable_3d_mode attribute and
columns will become 3D: <data_plot_settings enable_3d_mode="True">
In 3D mode you may want to show columns one over another - in other words: to cluster them along Z Axis. To do
this you should change scale mode of Y Axis to "Overlay":
XML Syntax
XML Code
01 <y_axis>
02 <scale mode="Overlay" />
03 </y_axis>
Positioning
With AnyChart you can place axes to any side of the chart, all you need to do is to adjust position attribute
of <y_axis> or<x_axis> nodes.
Positioning depends on plot type and inversion of axes, you will find list of all possible positining and inversion
settings in Axes Positioning and Inverting Templates.
XML Syntax
XML Code
01 <axes>
02 <y_axis position="Opposite" />
03 <x_axis position="Opposite" />
04 </axes>
Inversion
AnyChart allows to invert any axis: Y, X or any extra axis. Inversion is controlled by axis <scale>:
XML Syntax
XML Code
01 <y_axis>
02 <scale inverted="True" />
03 </y_axis>
Look at the demonstration of Y Axis inversion on the Single-series sample:
By default AnyChart calculates axis minimum and maximum automatically, you can see it on the scale inversion chart
sample above: minimal value on the Y Axis is 8.000, and maximum is 20.000. You can control these values by
setting maximum andminimum attributes of <scale> node:
XML Syntax
XML Code
01 <y_axis>
02 <scale minimum="0" maximum="50000" />
03 </y_axis>
Look at the demonstration of maximum and minimum values on the Single-series sample:
The main idea of styles is to segregate visualization and data definition. Visual appearance of columns is defined
using certain styles and then you just apply the style to the certain data elements. Style can be applied to all column
charts, data series or single column.
As a column chart is just a sub-type of bar chart, its style can be configured
in <bar_style> and <bar_series> nodes. On the image below you can see what bar_style consists of: fill
(including solid color fill, hatch fill, image fill and gradient fill), border and effects applied to whole column.
Styles are also used to make charts interactive, you can define how elements will be displayed by default, when
selected, when user moves cursor over an element, etc.
Simple style
Now, let's fins out how to create a simple style and apply it to the chart. As we've already told style consists of
several elements, here is an XML structure:
XML Syntax
XML Code
01 <bar_style name="style1">
02 <fill type="Solid" color="Gold" opacity="1" />
03 <border thickness="4" color="Rgb(86,86,26)" />
04 <hatch_fill enabled="True" type="DiagonalBrick" color="Gray" /
>
05 <effects>
06 <bevel enabled="true" highlight_opacity="0.4" shadow_opacity="0.4" distance="2" /
>
07 <drop_shadow enabled="true" opacity="0.3" />
08 </effects>
09 <states>
10 <hover>
11 <border color="DarkRed" thickness="6" />
12 <hatch_fill color="DarkRed" />
13 </hover>
14 </states>
15 </bar_style>
Using such settings we've created a style that defines columns of Gold color, rather thick border, hatch filled with
DiagonalBrick and a couple of effects. Also, we've defined that when user will move cursor over an element it will be
highlighted with a DarkRed thick border and hatch fill colored DarkRed too.
Now we will take a sample single series chart described above, define style in XML and apply it to all chart elements,
using<bar_series style="style1"/>
Now we will demonstrate how to apply different styles to different series and columns. To do it we will use multi-
series sample that was demonstrated above and create two more styles: "style2" and "style3", both inherited from
the "style1".
"style1" will be applied to "Quarter 1" series, "style2" will be applied to "Quarter 2" series and "style3" will be
applied to the column with a highest value (Note - we will find the highest value and set its style manually in this
sample. But with AnyChart it is possible to do that automatically using Thresholds, read more about it in Thresholds
tutorial).
Style 1:
XML Syntax
XML Code
01 <bar_style name="style1">
02 <fill type="Solid" color="Gold" opacity="1" />
03 <border thickness="4" color="Rgb(86,86,26)" />
04 <hatch_fill enabled="True" type="DiagonalBrick" color="Gray" /
>
05 <effects>
06 <bevel enabled="true" highlight_opacity="0.4" shadow_opacity="0.4" distance="2" /
>
07 <drop_shadow enabled="true" opacity="0.3" />
08 </effects>
09 <states>
10 <hover>
11 <border color="DarkRed" thickness="6" />
12 <hatch_fill color="DarkRed" />
13 </hover>
14 </states>
15 </bar_style>
Style 2:
This style is inherited from "style1" and the only thing changed is a color of the fill:
from "Gold" to "Rgb(180,180,255)". We've used styles inheritance to avoid duplication of the common settings.
XML Syntax
XML Code
01 <bar_style name="style2" parent="style1">
02 <fill color="Rgb(180,180,255)" />
03 </bar_style>
Style 3:
This style is also inherited from "style1" and the new color of the fill is "Rgb(255,170,170)". And again we've used
styles inheritance.
XML Syntax
XML Code
01 <bar_style name="style3" parent="style1">
02 <fill color="Rgb(255,170,170)" />
03 </bar_style>
Predefined styles
There are several predefined styles that you can use and modify with help of styles inheritance (setting them as a
parent styles for your styles). On the picture below you can see how these styles will change the appearance of the
columns and their names: "Default", "Silver", "AquaLight" and "AquaDark".
Note 1:
When you are inheriting from "AquaLight" and "AquaDark" styles you can change only the color, opacity, hatch-
fill and effects of the column.
Note 2:
When creating and applying styles to columns in 3D mode you can change only the color, opacity, hatch-fill and
effects of the column.
You can read more about styles and their usage in Styles tutorial.
Full reference of column chart style can be found in XML Reference,
particularly <bar_style> and <bar_series>nodes.
General things about tuning visual appearance, working with borders, colors, fills, etc. - can be found
in Visual Appearance Section
When formatting data labels text and tooltip we will use formatting keywords:
{%CategoryName} - to show sales manager name,
{%YValue} - to show his/her sales,
{%SeriesName} - to show period (quarter),
{%YPercentOfSeries} - to show every person sales percentage to total sales per quarter.
Using markers
Marker is an object with a specified shape, size, and color or an image used to mark and to identify chart elements.
AnyChart allows to add markers to any data element including columns.
In the sample below we will take single-series data described above and mark the highest column in series with
a "Star5" of the "Gold" color.
To make marker visually appealing we will create a style, that will tell AnyChart to set marker size to 16 pixels in
normal state, and make it bigger (22 pixels) when user moves cursor over an element.
Marker style "myMarker":
XML Syntax
XML Code
01 <marker_style name="myMarker" color="Gold">
02 <marker type="Star5" size="16" />
03 <states>
04 <hover>
05 <marker size="22" />
06 </hover>
07 </states>
08 </marker_style>
XML Syntax
XML Code
01 <point name="Peter" y="18000">
02 <marker enabled="True" style="myMarker" /
>
03 </point>
And here is a result - Peter sold more than others and we are showing this on the chart:
AnyChart seriously takes care of visualization and users convenience - that is why we have a number of ways to set
colors, for example, instead of "Rgb(180,77,77)" you can set "HSB" or "HTMLConstant" or "#HEXCode"- and the
color will be the same. Depending on your system/site/application design you may need - and use - any of this color
setting methods. But even this it is not all about colors in AnyChart: read more about setting colors below and in the
following Help Sections:
Color management
Color palettes
AnyChart allows to apply color palettes to all series or to the exact series. In the first case each next series will take
each next color from palette. If the number of the colors in palette is less than the number of series - palette will be
looped. If you have only one series it will be colored by the first color in the palette. To apply palette to all series we
have to set "palette"attribute in <data> node. Here it is: