Template:STV election graph
<graph> {
"legends":[ { "properties":{ "title":{ "fill":{ "value":"#54595d" } }, "labels":{ "fill":{ "value":"#54595d" } } }, "stroke":"color", "title":"Party", "fill":"color" } ], "scales":[ { "type":"ordinal", "name":"x", "zero":false, "domain":{ "data":"chart", "field":"x" }, "range":"width", "nice":true }, { "type":"linear", "name":"y", "domain":{ "data":"stats", "field":"sum_y" }, "zero":true, "range":"height", "nice":true }, { "domain":{ "data":"chart", "field":"series" }, "type":"ordinal", "name":"color", "range":[ "" ] } ], "version":2, "marks":[ { "type":"group", "marks":[ { "properties":{ "hover":{ "fill":{ "value":"#54595d" } }, "update":{ "fill":{ "scale":"color", "field":"series" } }, "enter":{ "y":{ "scale":"y", "field":"layout_start" }, "x":{ "scale":"x", "field":"x" }, "y2":{ "scale":"y", "field":"layout_end" }, "width":{ "scale":"x", "offset":-1, "band":true }, "fill":{ "scale":"color", "field":"series" } } }, "type":"rect" } ], "from":{ "data":"chart", "transform":[ { "field":"y", "type":"stack", "sortby":[ "-_id" ], "groupby":[ "x" ] }, { "groupby":[ "series" ], "type":"facet" } ] } } ], "height":300, "axes":[ { "type":"x", "title":"Count", "scale":"x", "properties":{ "title":{ "fill":{ "value":"#54595d" } }, "grid":{ "stroke":{ "value":"#54595d" } }, "ticks":{ "stroke":{ "value":"#54595d" } }, "axis":{ "strokeWidth":{ "value":2 }, "stroke":{ "value":"#54595d" } }, "labels":{ "fill":{ "value":"#54595d" } } }, "grid":false }, { "type":"y", "title":"Votes", "scale":"y", "format":"d", "properties":{ "title":{ "fill":{ "value":"#54595d" } }, "grid":{ "stroke":{ "value":"#54595d" } }, "ticks":{ "stroke":{ "value":"#54595d" } }, "axis":{ "strokeWidth":{ "value":2 }, "stroke":{ "value":"#54595d" } }, "labels":{ "fill":{ "value":"#54595d" } } }, "grid":false } ], "data":[ { "format":{ "parse":{ "y":"integer", "x":"string" }, "type":"json" }, "name":"chart", "values":[ ] }, { "transform":[ { "type":"aggregate", "summarize":{ "y":"sum" }, "groupby":[ "x" ] } ], "name":"stats", "source":"chart" } ], "width":300
} </graph>
![]() | This template employs intricate features of template syntax.
You are encouraged to familiarise yourself with its setup and parser functions before editing the template. If your edit causes unexpected problems, please undo it quickly, as this template may appear on a large number of pages. You can conduct experiments, and should test all major changes, in either this template's sandbox, the general template sandbox, or your user space before changing anything here. |
This template creates a formatted bar chart to display results of elections that use the single transferable vote, similar to {{Graph:Chart}}.
About
Each stage of the election is shown by a column, and the number of votes each candidate received at that stage is shown by a coloured bar within that column.
Non-transferable votes are calculated automatically by subtracting the total number of votes in any given round from the number of first-preference votes.
The template can currently display elections with up to 15 stages and 20 candidates.
Usage
The first two parameters are <syntaxhighlight lang="text" class="" style="" inline="1">Counts</syntaxhighlight> and <syntaxhighlight lang="text" class="" style="" inline="1">Candidates</syntaxhighlight>, both of which must be filled in for the template to function properly.
After this, each set of parameters relate to a particular candidate.
Parameter | Usage | Example |
---|---|---|
<syntaxhighlight lang="text" class="" style="" inline="1">1Party</syntaxhighlight> | Used to display the candidate's political party in the key. | <syntaxhighlight lang="text" class="" style="" inline="1">1Party=Fine Gael</syntaxhighlight> |
<syntaxhighlight lang="text" class="" style="" inline="1">1Colour</syntaxhighlight> | The party's colour, in hexadecimal format. Don't use meta templates, as they break the syntax. | <syntaxhighlight lang="text" class="" style="" inline="1">1Colour=#6699FF</syntaxhighlight> |
<syntaxhighlight lang="text" class="" style="" inline="1">1Count1</syntaxhighlight> | The number of votes the candidate received at the first count. Continues in the series <syntaxhighlight lang="text" class="" style="" inline="1">1CountN</syntaxhighlight>, where N is the number of the count. Don't use thousands separators, as this also breaks the syntax. | <syntaxhighlight lang="text" class="" style="" inline="1">1Count1=4999</syntaxhighlight> |
Candidates should either be ordered by first-preference votes (with the candidate with the highest vote using the <syntaxhighlight lang="text" class="" style="" inline="1">1</syntaxhighlight> set of parameters, the second highest using <syntaxhighlight lang="text" class="" style="" inline="1">2</syntaxhighlight> and so on), or by order of election (with the candidate elected first using the <syntaxhighlight lang="text" class="" style="" inline="1">1</syntaxhighlight> set of parameters, the candidate elected second <syntaxhighlight lang="text" class="" style="" inline="1">2</syntaxhighlight> and so on. Unsuccessful candidates should be ranked in reverse order of elimination, with the candidate eliminated first using the last set of parameters).
You may wish to enclose the bar chart in an {{Image frame}} template, which includes a caption and lets text wrap around the image.
Examples
Inserting...
{{STV election graph |Counts=3 |Candidates=3 |1Party=Labour |1Colour=#E4003B |1Count1=8000 |1Count2=700 |1Count3=6000 |2Party=Conservative |2Colour=#0087DC |2Count1=3500 |2Count2=4500 |2Count3=5500 |3Party=Liberal Democrats |3Colour=#FAA61A |3Count1=2500 |3Count2=2300 |3Count3=2100 }}
Produces... <graph> {
"legends":[ { "properties":{ "title":{ "fill":{ "value":"#54595d" } }, "labels":{ "fill":{ "value":"#54595d" } } }, "stroke":"color", "title":"Party", "fill":"color" } ], "scales":[ { "type":"ordinal", "name":"x", "zero":false, "domain":{ "data":"chart", "field":"x" }, "range":"width", "nice":true }, { "type":"linear", "name":"y", "domain":{ "data":"stats", "field":"sum_y" }, "zero":true, "range":"height", "nice":true }, { "domain":{ "data":"chart", "field":"series" }, "type":"ordinal", "name":"color", "range":[ "#E4003B","#0087DC","#FAA61A","#000000" ] } ], "version":2, "marks":[ { "type":"group", "marks":[ { "properties":{ "hover":{ "fill":{ "value":"#54595d" } }, "update":{ "fill":{ "scale":"color", "field":"series" } }, "enter":{ "y":{ "scale":"y", "field":"layout_start" }, "x":{ "scale":"x", "field":"x" }, "y2":{ "scale":"y", "field":"layout_end" }, "width":{ "scale":"x", "offset":-1, "band":true }, "fill":{ "scale":"color", "field":"series" } } }, "type":"rect" } ], "from":{ "data":"chart", "transform":[ { "field":"y", "type":"stack", "sortby":[ "-_id" ], "groupby":[ "x" ] }, { "groupby":[ "series" ], "type":"facet" } ] } } ], "height":300, "axes":[ { "type":"x", "title":"Count", "scale":"x", "properties":{ "title":{ "fill":{ "value":"#54595d" } }, "grid":{ "stroke":{ "value":"#54595d" } }, "ticks":{ "stroke":{ "value":"#54595d" } }, "axis":{ "strokeWidth":{ "value":2 }, "stroke":{ "value":"#54595d" } }, "labels":{ "fill":{ "value":"#54595d" } } }, "grid":false }, { "type":"y", "title":"Votes", "scale":"y", "format":"d", "properties":{ "title":{ "fill":{ "value":"#54595d" } }, "grid":{ "stroke":{ "value":"#54595d" } }, "ticks":{ "stroke":{ "value":"#54595d" } }, "axis":{ "strokeWidth":{ "value":2 }, "stroke":{ "value":"#54595d" } }, "labels":{ "fill":{ "value":"#54595d" } } }, "grid":false } ], "data":[ { "format":{ "parse":{ "y":"integer", "x":"string" }, "type":"json" }, "name":"chart", "values":[ { "y":8000, "series":"Labour", "x":"1" } ,{ "y":7000, "series":"Labour", "x":"2" } ,{ "y":6000, "series":"Labour", "x":"3" } ,{ "y":3500, "series":"Conservative", "x":"1" } ,{ "y":4500, "series":"Conservative", "x":"2" } ,{ "y":5500, "series":"Conservative", "x":"3" } ,{ "y":2500, "series":"Liberal Democrats", "x":"1" } ,{ "y":2300, "series":"Liberal Democrats", "x":"2" } ,{ "y":2100, "series":"Liberal Democrats", "x":"3" } ,{ "y":200, "series":"Non-transferable", "x":"2" } ,{ "y":400, "series":"Non-transferable", "x":"3" } ] }, { "transform":[ { "type":"aggregate", "summarize":{ "y":"sum" }, "groupby":[ "x" ] } ], "name":"stats", "source":"chart" } ], "width":150
} </graph>
Troubleshooting
- A party is listed twice in the key
- Make sure the party's name is spelt correctly, and that the colours are identical.
- The "non-transferable votes" bar is in a colour other than black
- Make sure the number of candidates is correct in the "Candidates" parameter.
- I want to make a graph for an election that has more that 20 candidates, or more than 15 counts
- Leave a message on the template's talk page, or add some extra parameters yourself. Be sure to test your edits in the sandbox before making any major changes.
- I get a "syntax error" message when I use the template
- Make sure there are no thousands separators, transcluded templates or duplicated parameters.