Aller au contenu

Modèle:ChartDirect

Une page de Wikipédia, l'encyclopédie libre.

Utilisation

[modifier le code]

Le modèle permet d'intégrer un graphique interactif sur Wikipédia.

Le graphique interactif avec l'extension Chart. Il utilize la fonctionalité transform et le module c:Module:Graph:Chart.

Avec standard templates

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

or Avec autres templates

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

or X/Y chart simple (idéal pour pie charts)

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

Paramètres

[modifier le code]

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

Paramètres du modèle[Modifier les données du modèle]

ParamètreDescriptionTypeÉtat
xx

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

Ligne de textefacultatif
xTitlexTitle

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

Ligne de textefacultatif
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.

Ligne de textefacultatif
yTitleyTitle

Legend value y-Axis

Ligne de textefacultatif
y1y1

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

Exemple
520,621,433
Nombresuggéré
y1Titley1Title

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

Exemple
population of Exampleville
Ligne de textesuggéré
xTypexType

Data format of the x-Axis

Valeurs suggérées
number integer date string
Ligne de textefacultatif
yTypeyType

Data format of the x-Axis

Valeurs suggérées
number integer date string
Ligne de textefacultatif
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.

Valeurs suggérées
bar pie line area
Par défaut
bar
Ligne de textefacultatif
swapswap

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

Par défaut
0
Booléenfacultatif
Display as thumbnailthumb 1

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

Valeurs suggérées
thumb
Exemple
thumb
Ligne de textefacultatif
Alignmentalign 2

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

Valeurs suggérées
left right center
Ligne de textefacultatif
Widthwidth 3

Width in pixels or percent

Valeurs suggérées
400px 600px 50% 100%
Ligne de textefacultatif
Captioncaption 4

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

Exemple
This is a chart caption.
Chaînefacultatif
Chart definitionchart definition

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

Exemple
Example.chart
Ligne de texteobligatoire
Source attributionsource

Option to cite a source

Exemple
some reference
Ligne de textefacultatif
Borderborder

Set to "1" to enable a border

Valeurs suggérées
1
Exemple
1
Booléenfacultatif
CSS stylesstyle

Additional CSS styles (beyond width and border)

Exemple
border-width:5px;
Ligne de textefacultatif
Hide sourcehideSource

Set to any value to disable linking to the source

Valeurs suggérées
1
Exemple
1
Booléenfacultatif

simple bar plot, multiple data rows

[modifier le code]
{{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

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


full width

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


other data source and border

[modifier le code]
{{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

[modifier le code]
{{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

[modifier le code]
{{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
}}
PopulationAnnée5010015020025030035019801990200020102020Population


aligned and fixed width thumbnail

[modifier le code]
{{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
}}
PopulationAnnée5010015020025030035019801990200020102020Population


centered, fixed width, border, caption and source

[modifier le code]
{{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
}}
PopulationAnnée5010015020025030035019801990200020102020Population
Population of Exampleville Source: per reference xyz



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

[modifier le code]

Create own templates

[modifier le code]

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

[modifier le code]

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

[modifier le code]

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