Difference between revisions of "Template:Graph:CategoryPie"

From Public Play Space Community
Line 1: Line 1:
  <graph>
  <graph>
{
{
   "width": 100,
  "$schema": "https://vega.github.io/schema/vega/v4.json",
   "height": 100,
   "width": 200,
   "type": "pie",
   "height": 200,
"x": "A,B,C,D,E,F,G,H,I",
  "autosize": "fit",
"y":"100,200,150,300,100,100,150,50,200"
 
   "data": [
    {
      "name": "table",
      "values": [
        {"id": "Biology", "field": 4},
        {"id": "Chemistry", "field": 8},
        {"id": "Computer Science", "field": 2},
        {"id": "Programming", "field": 2},
        {"id": "Sociology", "field": 8}
      ],
      "transform": [
        {"type": "formula", "expr": "datum.id + ': ' + datum.field", "as": "tooltip"},
        {
          "type": "pie",
          "field": "field",
          "startAngle": 0,
          "endAngle": 6.29,
          "sort": true
        }
      ]
    }
  ],
 
  "scales": [
    {
      "name": "color",
      "type": "ordinal",
      "domain": {"data": "table", "field": "id"},
      "range": {"scheme": "category20c"}
    }
  ],
 
  "marks": [
    {
      "type": "arc",
      "from": {"data": "table"},
      "encode": {
        "enter": {
          "fill": {"scale": "color", "field": "id"},
          "x": {"signal": "width / 2"},
          "y": {"signal": "height / 2"},
          "startAngle": {"field": "startAngle"},
          "endAngle": {"field": "endAngle"},
          "innerRadius": {"value": 60},
          "outerRadius": {"signal": "width / 2"},
          "cornerRadius": {"value": 0},
          "tooltip": {"field": "tooltip"}
        }
      }
    }
  ]
}
}
  </graph>
  </graph>

Revision as of 07:46, 19 May 2020