Template talk:Graph:PieChart

Example usage:

Stacked pie
{ "version": 2, "height": 160, "width": 160, "legends": [{"title": "Fruits","fill": "color"}], "padding": "auto", "data": [ {     "name": "table", "values": [ {"x": "peach","y": 100,"z": 2}, {"x": "plums","y": 32,"z": 4}, {"x": "bluebe","y": 180,"z": 3}, {"x": "strawb","y": 46,"z": 7}, {"x": "banan","y": 21,"z": 5} ]   }  ],  "scales": [ {     "name": "color", "range": "category20", "domain": {"data": "table","field": "x"}, "type": "ordinal" } ],  "marks": [ {     "type": "arc", "from": { "data": "table", "transform": [{"field": "y","type": "pie"}] },     "properties": { "enter": { "innerRadius": {"value": 100}, "stroke": {"value": "white"}, "startAngle": {"field": "layout_start"}, "outerRadius": {"value": 150}, "endAngle": {"field": "layout_end"}, "fill": {"field": "x","scale": "color"} }     }    },    {      "type": "arc", "from": { "data": "table", "transform": [{"field": "z","type": "pie"}] },     "properties": { "enter": { "innerRadius": {"value": 40}, "stroke": {"value": "white"}, "startAngle": {"field": "layout_start"}, "outerRadius": {"value": 90}, "endAngle": {"field": "layout_end"}, "fill": {"field": "x","scale": "color"} }     }    }  ] } A pie chart is a stacked bar chart in polar coordinates for a single category. Above an example of a stacked pie chart, that is with mutiple - here two - categories. The Vega specification can probably be optimized somehow. Any use within Wikipedia? Need for a separate template, or is this somehow to be included within the template? Ad Huikeshoven (talk) 22:19, 27 December 2015 (UTC)


 * Wow, this is pretty cool! One usage idea - it could be used for showing how distribution of something has changed with time, e.g. each ring represents a year. As for Vega itself - I think it would be better to use "group" mark that wraps the arc (similar to this or this examples). With groups, it should even be possible to integrate it into the current template, or to build a separate template to keep things simple. --Yurik (talk) 04:08, 28 December 2015 (UTC)
 * group, facet and groupby aren't really straightforward, but here you go:

{ "version": 2, "width": 150, "height": 150, "legends": [{"title": "Fruits","fill": "color"}], "data": [ { 	"name": "table", "values": [ {"year": "2010","category": "Berries","value": 10}, {"year": "2010","category": "Plums","value": 12}, {"year": "2010","category": "Oranges","value": 3}, {"year": "2010","category": "Apples","value": 7}, {"year": "2015","category": "Berries","value": 8}, {"year": "2015","category": "Plums","value": 4}, {"year": "2015","category": "Oranges","value": 5}, {"year": "2015","category": "Apples","value": 9} ]	} ],  "scales": [ { 	"name": "radius", "type": "ordinal", "domain": {"data": "table","field": "year"}, "range": "height" },	{ 	"name": "color", "range": "category20", "domain": {"data": "table","field": "category"}, "type": "ordinal" } ],  "marks": [ { 	"type": "group", "from": { "data": "table", "transform": [{"type": "facet","groupby": ["year"]}] }, 	"marks": [ {     	"name": "stacked pie", "type": "arc", "from": {"transform": [{"field": "value","type": "pie"}]}, "properties": { "enter": { "innerRadius": { "scale": "radius", "field": "year", "offset": 25 },         	"stroke": {"value": "white"}, "startAngle": {"field": "layout_start"}, "outerRadius": { "scale": "radius", "field": "year", "offset": 75 },         	"endAngle": {"field": "layout_end"}, "fill": {"field": "category","scale": "color"} }     	}    	},    	{      	"type": "text", "properties": { "enter": { "radius": { "scale": "radius", "field": "year", "offset": 30 },         	"theta": {"value":1.2}, "x": 100, "y": 100, "text": {"field": "year"}, "fill": {"value": "#eec"}, "fontSize": {"value": 18} }     	}    	}  	]	}  ] }  {  "version": 2, "width": 150, "height": 150, "legends": [{"title": "Fruits","fill": "color"}], "data": [ { 	"name": "table", "values": [ {"year": "2010","category": "Berries","value": 10}, {"year": "2010","category": "Plums","value": 12}, {"year": "2010","category": "Oranges","value": 3}, {"year": "2010","category": "Apples","value": 7}, {"year": "2015","category": "Berries","value": 8}, {"year": "2015","category": "Plums","value": 4}, {"year": "2015","category": "Oranges","value": 5}, {"year": "2015","category": "Apples","value": 9} ]	} ],  "scales": [ { 	"name": "radius", "type": "ordinal", "domain": {"data": "table","field": "year"}, "range": "height" },	{ 	"name": "color", "range": "category20", "domain": {"data": "table","field": "category"}, "type": "ordinal" } ],  "marks": [ { 	"type": "group", "from": { "data": "table", "transform": [{"type": "facet","groupby": ["year"]}] }, 	"marks": [ {     	"name": "stacked pie", "type": "arc", "from": {"transform": [{"field": "value","type": "pie"}]}, "properties": { "enter": { "innerRadius": { "scale": "radius", "field": "year", "offset": 25 },         	"stroke": {"value": "white"}, "startAngle": {"field": "layout_start"}, "outerRadius": { "scale": "radius", "field": "year", "offset": 75 },         	"endAngle": {"field": "layout_end"}, "fill": {"field": "category","scale": "color"} }     	}    	},    	{      	"type": "text", "properties": { "enter": { "radius": { "scale": "radius", "field": "year", "offset": 30 },         	"theta": {"value":1.2}, "x": 100, "y": 100, "text": {"field": "year"}, "fill": {"value": "#eec"}, "fontSize": {"value": 18} }     	}    	}  	]	}  ] } Yurik thanks for challenging me :) Ad Huikeshoven (talk) 17:57, 28 December 2015 (UTC)
 * Ad Huikeshoven, awesome!!! I played with it a bit, seems really good!  I found graph to be easier to read if the gap is only one pixel - looks a bit more readable imho, but that probably depends on the specifics of the data. I wonder if radius offsets should be somehow tied to the scales instead of being hardcoded. Also, usually I prefer shorter labels for the data, one char best.  But I'm neat-picking, it looks awesome :)) --Yurik (talk) 18:46, 28 December 2015 (UTC)

Conflict with Blackscreen gadget
This template conflicts with the blackscreen gadget. There is a thread about this at Village_pump_(technical). DuncanHill (talk) 13:37, 4 June 2018 (UTC)

Legend font too small and backward compatibility with Template:Pie chart
Is it just me who find the legend key in this too small (and ugly!)? Also, shouldn't this template be made backward compatible with pie chart for easy conversion? Cheers. Guarapiranga (talk) 01:39, 9 November 2019 (UTC)