Edge Rewrite
// HTMLRewriter · presentation

This page was redesigned at the edge.

Cloudflare fetched the original article and streamed it through HTMLRewriter to apply an entirely new visual system without rebuilding the source page.

Jump to content

Template:ChartDirect/doc

From Wikipedia, the free encyclopedia

This template allows to generate simple plots using the Chart Feature. It is based on the transform functionality and used the commons module c:Module:Graph:Chart.

Copy templates

[edit]


With default templates

{{ChartDirect
| type       = 
| x= | y1= | y1Title= 
| y2= | y2Title=
| y3= | y3Title=
| y4= | y4Title=
| y5= | y5Title= 
| thumb      =
| align      = 
| width      = 
| border     = 
| style      = 
| caption    =
| source     = 
}}

or With own template

{{ChartDirect
| chart     = 
| x= | y1= | y1Title= 
| y2= | y2Title=
| y3= | y3Title=
| y4= | y4Title=
| y5= | y5Title= 
| thumb      =
| align      = 
| width      = 
| border     = 
| style      = 
| caption    =
| source     = 
}}

or Simple X/Y chart (ideal for pie charts)

{{ChartDirect
| type       = 
| x= | y=
| thumb      =
| align      = 
| width      = 
| border     = 
| style      = 
| caption    =
| source     = 
}}


Examples

[edit]

simple bar plot, multiple data rows

[edit]
{{ChartDirect
|type=bar
|x=Oranges, Strawberries, Pineapple
|xTitle=Fruit
|y=58,23,77
| align      = left
| width      = 400px
}}
020406080FruitOrangesStrawberriesPineapple

simple bar plot, one data row only

[edit]
{{ChartDirect
|type=bar
|y=58,23,77
|yTitle=amount
| align      = left
| width      = 400px
}}
020406080123amount

full width

[edit]
{{ChartDirect
|type=pie
|x=Oranges, Strawberries, Pineapple
|y=58,23,77
}}
OrangesStrawberriesPineappleOrangesStrawberriesPineapple

other data source and border

[edit]
{{ChartDirect
|x=1,5,100
|y1=20,4,80
|y1Title=Oranges
|y2=3,6,9
|y2Title=Bananas
|y3=20,18,15
|y3Title=Apples
|y4=3,25,15
|y4Title=Mangos
|y5=5,5,15
|y5Title=Grapes
| border     = 1
}}
02040608015100OrangesBananasApplesMangosGrapes

thumbnail

[edit]
{{ChartDirect
| thumb
|title=Fruit trend
|type=line
|x=1,5,100
|y1=20,4,80
|y1Title=Oranges
|y2=3,6,9
|y2Title=Bananas
|y3=20,18,15
|y3Title=Apples
|y4=3,25,15
|y4Title=Mangos
|y5=5,5,15
|y5Title=Grapes
}}
020406080020406080100OrangesBananasApplesMangosGrapes

aligned and fixed width

[edit]
{{ChartDirect
| chart      = Template line population by year.chart
| align      = right
| width      = 400px
|x=1980,1990,2000,2010,2020
|y1=98,87,201,252,325
|y1Title=Population
}}
PopulationYear5010015020025030035019801990200020102020Population

aligned and fixed width thumbnail

[edit]
{{ChartDirect
| thumb
| align      = left
| width      = 400px
| chart      = Template line population by year.chart
|x=1980,1990,2000,2010,2020
|y1=98,87,201,252,325
|y1Title=Population
}}
PopulationYear5010015020025030035019801990200020102020Population

centered, fixed width, border, caption and source

[edit]
{{ChartDirect
| chart      = Template line population by year.chart
| x=1980,1990,2000,2010,2020
| y1=98,87,201,252,325
| y1Title=Population
| align      = center
| width      = 400px
| caption    = Population of Exampleville
| source     = per reference xyz
}}
PopulationYear5010015020025030035019801990200020102020Population
Population of Exampleville Source: per reference xyz

swap

[edit]

Demonstration of the swap parameter effect. Intention: figuring out in an easy way what is the best way to plot rows and columns.

{{ChartDirect
 |y1Title=Bregenz|y2Title=Eisenstadt|y3Title=Graz|y4Title=Innsbruck|y5Title=Klagenfurt|y6Title=Linz|y7Title=Salzburg|y8Title=St. Pölten|y9Title=Wien
 |x=traffic choice, air quality, bicycle traffic, public transport, parking space, pedestrians, car alternatives, MEAN
 |y1=6.25,10,3,5.75,3.75,6.75,3,5.5
 |y2=3,9,1.75,1.75,4,7,3.75,4.32
 |y3=5.75,3.75,2.5,6.75,4.75,6,4.5,4.86
 |y4=7,8.25,4.25,7.25,4.75,4,3.5,5.57
 |y5=3.5,8.75,6,5.75,3.25,5,3.5,5.11
 |y6=5,4.5,4,6.75,4.25,6.25,3,4.82
 |y7=5.5,5.25,3,5,4.5,6,3,4.61
 |y8=4.5,9.5,5.25,2.5,3,4.25,3.25,4.61
 |y9=7,5,6.5,7.75,7.25,5.5,6.75,6.54
}}
0246810traffic choicepublic transportcar alternativesBregenzEisenstadtGrazInnsbruckKlagenfurtLinzSalzburgSt. PöltenWien
{{ChartDirect
 |y1Title=Bregenz|y2Title=Eisenstadt|y3Title=Graz|y4Title=Innsbruck|y5Title=Klagenfurt|y6Title=Linz|y7Title=Salzburg|y8Title=St. Pölten|y9Title=Wien
 |x=traffic choice, air quality, bicycle traffic, public transport, parking space, pedestrians, car alternatives, MEAN
 |y1=6.25,10,3,5.75,3.75,6.75,3,5.5
 |y2=3,9,1.75,1.75,4,7,3.75,4.32
 |y3=5.75,3.75,2.5,6.75,4.75,6,4.5,4.86
 |y4=7,8.25,4.25,7.25,4.75,4,3.5,5.57
 |y5=3.5,8.75,6,5.75,3.25,5,3.5,5.11
 |y6=5,4.5,4,6.75,4.25,6.25,3,4.82
 |y7=5.5,5.25,3,5,4.5,6,3,4.61
 |y8=4.5,9.5,5.25,2.5,3,4.25,3.25,4.61
 |y9=7,5,6.5,7.75,7.25,5.5,6.75,6.54
 |swap=1
}}
0246810BregenzInnsbruckSalzburgtraffic choiceair qualitybicycle trafficpublic transportparking spacepedestrianscar alternativesMEAN

Further information

[edit]

Create own templates

[edit]

By using the parameter chart an own chart can be selected as template. The advantage is a better adaptability of the chart, especially descriptions of the axes. It is important to include the Transform-section for the commons module.

Transform-Section

[edit]

More detailed information can be found in the commons module c:Module:Graph:Chart.

    "transform": {
        "module": "Graph:Chart",
        "function": "main",
        "args": {
            "x": "1,5",
            "y": "10,15"
        }
    },
    "source": "Graph:Chart.tab"

Troubleshooting

[edit]

1) error message when generating the plot

hint: for each data row y1...y15, one corresponding y1Title...y15Title must be defined

2) the x-axis is interpreted as a number

hint: setting xType can force a different behaviour (usually xType=string)

3) the y-axis should be based on zero

response: unfortunately, this cannot be configured at the moment with the chart extension. See Phab:Task T385344. Area und Line charts are not going to zero. Bar charts are going to zero. Therefore bar charts can be a workaround for this limitation.

4) height of the plot should be configurable

response: unfortunately, this cannot be configured at the moment with the chart extension. See Phab:Task T376845.

5) the plot shows in different colors, but it should be one color only

hint: change y to y1 and yTitle to y1Title

TemplateData

[edit]

Includes a chart with source attribution and allows adjusting alignment, width, and border.

Template parameters

ParameterDescriptionTypeStatus
xx

Values x-Axis. Note: with pie charts either use only x and y, or use y1-y15 as needed

Lineoptional
xTitlexTitle

Option to show a Title on the X-axis, if the other values are just x and y (no y1-y15)

Lineoptional
yy

Values y-Axis. Note: values y and y1-15 cannot be combined. If y is used, every new entry will be interpreted as one additional data row. Data rows are limited to 15.

Lineoptional
yTitleyTitle

Legend value y-Axis

Lineoptional
y1y1

Values first row y-Axis. Further parameters y2-y15 are supported

Example
520,621,433
Numbersuggested
y1Titley1Title

Legend value y-Axis. It is necessary for each y-Axis row (e.g. y1 and y1Title). Additional parameters y2-y15 are supported

Example
population of Exampleville
Linesuggested
xTypexType

Data format of the x-Axis

Suggested values
number integer date string
Lineoptional
yTypeyType

Data format of the x-Axis

Suggested values
number integer date string
Lineoptional
Use of predefined template chartstype

Data:...chart on Wikimedia Commons. Predefined charts based on the selected plot type. If parameter <code>chart</code> or <code>definition</code> is set, this parameter will be ignored.

Suggested values
bar pie line area
Default
bar
Lineoptional
swapswap

Option to transpose an already defined chart (swapping rows/columns). Up to 15 values can be swapped per data row.

Default
0
Booleanoptional
Display as thumbnailthumb 1

Set to any value to display in a gray box like an image thumbnail

Suggested values
thumb
Example
thumb
Lineoptional
Alignmentalign 2

Chart alignment, either "left", "right", or "center"

Suggested values
left right center
Lineoptional
Widthwidth 3

Width in pixels or percent

Suggested values
400px 600px 50% 100%
Lineoptional
Captioncaption 4

Caption to display before the source information. Make sure to use ending punctuation.

Example
This is a chart caption.
Stringoptional
Chart definitionchart definition

Chart on Wikimedia Commons, without the "Data:" prefix

Example
Example.chart
Linerequired
Source attributionsource

Option to cite a source

Example
some reference
Lineoptional
Borderborder

Set to "1" to enable a border

Suggested values
1
Example
1
Booleanoptional
CSS stylesstyle

Additional CSS styles (beyond width and border)

Example
border-width:5px;
Lineoptional
Hide sourcehideSource

Set to any value to disable linking to the source

Suggested values
1
Example
1
Booleanoptional

See also

[edit]