Malline:Esimerkkikaaviot/Population of London example/graph

Wikikirjastosta


{{Esimerkkikaaviot/Population of London example}}
[ source data ]<graph>

{
  //
  // ATTENTION: This code is maintained at https://www.mediawiki.org/wiki/Template:Graph:Population_history
  //            Please do not modify it anywhere else, as it may get copied and override your changes.
  //            Suggestions can be made at https://www.mediawiki.org/wiki/Template_talk:Graph:Population_history
  //

  "version": 2,
  "width": 400,
  "height": 200,

  "data": [
    {
      "name": "table",
"url": "wikidatasparql:///?query={{{query}}}",
      "format": { "type": "json" },
      // Convert year integer (2016) into a date object (2016-01-01)
      "transform": [
      	// Optionally filter data with an template expression parameter
      	// e.g.  filter = datum.year > 1900 && datum.year < 2000

      	{ "type": "formula", "field": "date", "expr": "datetime(datum.year,0,1)" }
      ]
    },

    // Each annotation is expected to be an integer year, string text,
    // and optional string color (e.g. "#4d2800")
    {
      "name": "annotations",
"values": [],
      "transform": [
        { "type": "formula", "field": "date", "expr": "datetime(datum.year,0,1)" },
        { "type": "formula", "field": "color", "expr": "datum.color||'#000'" }
      ]
    }
  ],

  "scales": [
    // The dates are scaled to the "x" axis - the width of the graph
    {
      "name": "x",
      "type": "time",
      "range": "width",
      "domain": {"data": "table","field": "date"}
    },
    {
      "name": "y",
      "type": "linear",
      "range": "height",
      "domain": {"data": "table","field": "population"},
      "clamp": true,

      "nice": true
    }
  ],

  // Simple axis with horizontal grid lines
  "axes": [
    {"type": "x", "scale": "x", "ticks": 5},
    {"type": "y", "scale": "y", "ticks": 5, "grid": true, "orient":"right"}
  ],

  // The graph is drawn with two elements a thick line at the top,
  // and a semi-transparent area below
  "marks": [
    {
      "type": "area",
      "from": {"data": "table"},
      "properties": {
        "enter": {
          "x": {"scale": "x", "field": "date"},
          "y": {"scale": "y", "value": 0},
          "y2": {"scale": "y", "field": "population"},
          "fill": {"value": "#99B2CC"},
          "fillOpacity": {"value": 0.35},
          "interpolate": {"value": "monotone"}
        }
      }
    },
    // If annotations are given, draw dashed line with associated text
    {
      "type": "rule",
      "from": {"data": "annotations"},
      "properties": {
        "enter": {
          "x": {"scale": "x", "field":"date"},
          "y": {"value": 0},
          "y2": {"signal": "height"},
          "stroke": {"field": "color"},
          "strokeWidth": {"value": 2},
          "opacity": {"value": 0.6},
          "strokeDash": {"value": [8,3]}
        }
      }
    },
    {
      "type": "line",
      "from": {"data": "table"},
      "properties": {
        "enter": {
          "x": {"scale": "x","field": "date"},
          "y": {"scale": "y","field": "population"},
          "stroke": {"value": "#99B2CC"},
          "strokeWidth": {"value": 3},
          "interpolate": {"value": "monotone"}
        }
      }
    },
    // The small white circles should be drawn after annotations but before text
    {
      "type": "symbol",
      "from": {"data": "table"},
      "properties": {
        "enter": {
          "x": {"scale": "x","field": "date"},
          "y": {"scale": "y","field": "population"},
          "stroke": {"value": "#99B2CC"},
          "fill": {"value": "#fff"},
          "size": {"value": 30}
        }
      }
    },
    // Draw title at the top of the graph
   {
      "type": "text",
      "properties": {
        "enter": {
          "x": {"value": 0},
          "y": {"value": 15},
          "text": {"value": ""},
          "align": {"value": "left"},
          "baseline": {"value": "bottom"},
          "fill": {"value": "#000"}
        }
      }
    }
  ]
}

</graph>

[ source data ]