Jump to content

Template:Graph:Lines

Permanently protected template
From Wikipedia, the free encyclopedia

This is an old revision of this page, as edited by Yurik (talk | contribs) at 03:36, 22 December 2016. The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

<graph>
{
  //
  // ATTENTION: This code is maintained at https://www.mediawiki.org/wiki/Template:Graph:Lines
  //            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:Lines
  //

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

  "data": [{
    "name": "chart",
    "url": "tabular:///",
    "format": {"type": "json", "property": "data"

    },
    "transform": [
    	// Convert xField parameter into a field "_xfield"
    	{"type": "formula", "field": "_xfield", "expr": 
"datetime(datum.year, 0, 1)"
      },
      {"type": "fold", "fields": [{{{series}}}]}
    ]
  },
  {
    "name": "labels",
    "url": "tabular:///",
    "format": {"type": "json", "property": "schema.fields"}
  }],
  "scales": [
    {
      "name": "x",
      "type": "time",
      "domain": {"data": "chart", "field": "_xfield"},
      "range": "width",



    },
    {
      "name": "y",
      "type": "linear",
      "range": "height",
      "domain": {"data": "chart", "field": "value"},



    },
    {
      "name": "color",
      "type": "ordinal",
      "domain": {"data": "chart", "field": "key"},
      "range": "category10"
    },
    {
      "name": "labels",
      "type": "ordinal",
      "domain": {"data": "labels", "field": "name"},
      "range": {"data": "labels", "field": "title"},
    }
  ],

  "axes": [
    {"scale": "x", "type": "x", "ticks": 7


},
    {"scale": "y", "type": "y"


}
  ],

  "marks": [
    // Group data by the "key", and draw lines, one line per key
    {
      "type": "group",
      "from": {
        "data": "chart",
        "transform": [{"groupby": ["key"], "type": "facet"}]
      },
      "marks": [
        {
          "type": "line",
          "properties": {
            "enter": {
              "y": {"scale": "y", "field": "value"},
              "x": {"scale": "x", "field": "_xfield"},
              "stroke": {"scale": "color", "field": "key"},
              "interpolate": {"value": "monotone"},
              "strokeWidth": {"value": 2.5}
            }
          }
        }
      ],
    }


  ]
}
</graph>