Extension:Graph/Demo/Pageviews2


<graph>

{
  "version": 2,
  "width": 400,
  "height": 200,
  "data": [
    {
      "name": "pv-desktop",
      "url": "wikirest://wikimedia.org/api/rest_v1/metrics/pageviews/per-article/en.wikipedia/desktop/user/Main_Page/daily/2024100200/2024110100",
      "format": {"type": "json","property": "items"},
      "transform": [
        {
          "type": "formula",
          "field": "date",
          "expr": "datetime(parseInt(substring(datum.timestamp,0,4)),parseInt(substring(datum.timestamp,4,6))-1,parseInt(substring(datum.timestamp,6,8)))"
        }
      ]
    },
    {
      "name": "pv-mobileweb",
      "url": "wikirest://wikimedia.org/api/rest_v1/metrics/pageviews/per-article/en.wikipedia/mobile-web/user/Main_Page/daily/2024100200/2024110100",
      "format": {"type": "json","property": "items"},
      "transform": [
        {
          "type": "formula",
          "field": "date",
          "expr": "datetime(parseInt(substring(datum.timestamp,0,4)),parseInt(substring(datum.timestamp,4,6))-1,parseInt(substring(datum.timestamp,6,8)))"
        }
      ]
    },
    {
      "name": "pv-mobileapp",
      "url": "wikirest://wikimedia.org/api/rest_v1/metrics/pageviews/per-article/en.wikipedia/mobile-app/user/Main_Page/daily/2024100200/2024110100",
      "format": {"type": "json","property": "items"},
      "transform": [
        {
          "type": "formula",
          "field": "date",
          "expr": "datetime(parseInt(substring(datum.timestamp,0,4)),parseInt(substring(datum.timestamp,4,6))-1,parseInt(substring(datum.timestamp,6,8)))"
        }
      ]
    },
    {
      "name": "alldata",
      "source": "pv-desktop",
      "transform": [
        {
          "type": "formula",
          "field": "Desktop",
          "expr": "datum.views"
        },
        {
          "type": "lookup",
          "on": "pv-mobileweb",
          "onKey": "date",
          "keys": ["date"],
          "as": ["mobilecount"]
        },
        {
          "type": "formula",
          "field": "Mobile",
          "expr": "datum.mobilecount.views"
        },
        {
          "type": "lookup",
          "on": "pv-mobileapp",
          "onKey": "date",
          "keys": ["date"],
          "as": ["appcount"]
        },
        {
          "type": "formula",
          "field": "App",
          "expr": "datum.appcount.views"
        },
        {"type": "fold", "fields": ["Desktop", "Mobile", "App"]}
      ]
    },
    {
      "name": "stats",
      "source": "alldata",
      "transform": [
        {
          "type": "aggregate",
          "groupby": ["date"],
          "summarize": [{"field": "value", "ops": ["sum"]}]
        }
      ]
    }
  ],
  "scales": [
    {
      "name": "x",
      "type": "time",
      "range": "width",
      "domain": {"data": "alldata","field": "date"}
    },
    {
      "name": "y",
      "type": "linear",
      "range": "height",
      "nice": true,
      "domain": {"data": "stats", "field": "sum_value"}
    },
    {
      "name": "c",
      "type": "ordinal",
      "range": ["#B2912F","#5DA5DA","#FAA43A"],
      "domain": {"data": "alldata", "field": "key"}
    }
  ],
  "axes": [
    {"type": "x","scale": "x","ticks": 5},
    {"type": "y","scale": "y"}
  ],
  "legends": [
    {"fill": "c"}
  ],
  "marks": [
    {
      "type": "group",
      "from": {
        "data": "alldata",
        "transform": [
          {"type": "stack", "groupby": ["date"], "sortby": ["key"], "field": "value"},
          {"type": "facet", "groupby": ["key"]}
        ]
      },
      "marks": [
        {
          "type": "area",
          "properties": {
            "enter": {
              "interpolate": {"value": "monotone"},
              "x": {"scale": "x", "field": "date"},
              "y": {"scale": "y", "field": "layout_start"},
              "y2": {"scale": "y", "field": "layout_end"},
              "fill": {"scale": "c", "field": "key"},
              "fillOpacity": {"value": 1}
            }
          }
        }
      ]
    }
  ]
}

</graph>