Template:Bar chart
City | Population |
---|
![]() | {{Bar chart}} handles up to 4 columns and 30 rows of data. |
![]() | This template uses TemplateStyles: |
This template can be used to create a horizontal bar chart, scrolling down a page, in a format which can be parsed by text-based web browsers. The data items can be simple numbers, or the result of calculations based on template parameters.
Each data number (data1=7, data2=23...), in column 1, is scaled to parameter "data_max=" and the bars are sized by width in em
units, such as "bar_width=16". By default, the data numbers are shown within each bar, but might display outside a bar when a relatively small number generates a short bar. Each bar can also have a comment, such as "comment7=xx" to show "(xx)" after the number in bar 7.
For a 2-column bar chart, the 2nd column items have prefix "col2_" such as scale maximum, col2_data_max=110, and col2_data3=67 with col2_comment3=zz. See below: "Example with two data columns". Each bar chart can be formatted typically within 1/5 second.
Usage and parameters
- The use of text other than numbers and proper punctuation in a data field will result in an Expression error.
<syntaxhighlight lang="wikitext" style="overflow: auto;">
City | Population |
---|
</syntaxhighlight>
Alignment
To float the bar chart on the right of the page, use <syntaxhighlight lang="wikitext"> | float = right </syntaxhighlight> To float the bar chart on the left of the page, use <syntaxhighlight lang="wikitext"> | float = left </syntaxhighlight> To float the bar chart to the center of the page, use <syntaxhighlight lang="wikitext"> | float = center </syntaxhighlight> The default is none.
Caption
To add a caption to the bottom of the chart, use <syntaxhighlight lang="wikitext"> | caption = </syntaxhighlight>
Empty cells
Use – or — (or a similar dash character) as a placeholder in a cell where there is no data available. Leaving a cell completely blank can sometimes cause columns to be misaligned.
Example
City | Population |
---|---|
City1 | |
City2 | |
City3 | |
City4 | |
City5 |
<syntaxhighlight lang="wikitext" style="overflow: auto">
City | Population |
---|---|
City1 | |
City2 | |
City3 | |
City4 | |
City5 |
</syntaxhighlight>
Example with comments
Year | Passengers (% change from prior year) |
---|---|
2003-04 | |
2004-05 | |
2005-06 | |
2006-07 | |
2007-08 | |
2008-09 | |
2009-10 |
<syntaxhighlight lang="wikitext" style="overflow: auto">
Year | Passengers (% change from prior year) |
---|---|
2003-04 | |
2004-05 | |
2005-06 | |
2006-07 | |
2007-08 | |
2008-09 | |
2009-10 |
</syntaxhighlight>
Example with two data columns
Fiscal year | Revenue passengers | Aircraft movements |
---|---|---|
2001-02 | ||
2002-03 | ||
2003-04 | ||
2004-05 | ||
2005-06 | ||
2006-07 | ||
2007-08 | ||
2008-09 | ||
2009-10 |
<syntaxhighlight lang="wikitext" style="overflow: auto">
Fiscal year | Revenue passengers | Aircraft movements |
---|---|---|
2001-02 | ||
2002-03 | ||
2003-04 | ||
2004-05 | ||
2005-06 | ||
2006-07 | ||
2007-08 | ||
2008-09 | ||
2009-10 |
</syntaxhighlight>
See also
- {{Historical populations}} (meets accessibility guidelines)
- {{Bar box}}, shows bar chart with a text column after the bars or bar-pairs
- {{Bartable}}
- {{Composition bar}}
- {{Pie chart}}, shows pie wedges in a circular pie chart
- {{Brick chart}}, shows brick segments in a rectangular "pie chart"
- {{Vertical bar chart}} (does not meet accessibility guidelines due to the lack of alternative text)
- {{Data bars}}
- WP:Graphs