Template:Graph:Horizontal bars

From Bonkipedia
Template documentation


This graph's main version resides at Template:Graph:Stacked. Please make or suggest all the changes there, and copy it everywhere else (until the copying is automated)

{{Graph:Horizontal bars
| table=Wikimedia/CEE Spring/Statistics/MMXVI/Per country sums (general).tab
| xField=country
| series="articles", "created", "improved"
| title=Per country sums
| legend=Types
}}
<graph>

{

 //
 // ATTENTION: This code is maintained at https://www.mediawiki.org/wiki/Template:Graph:Horizontal_bars
 //            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:Graph:Horizontal_bars
 //
 // Template translation is in https://commons.wikimedia.org/wiki/Data:Original/Template:Graphs.tab
 //
 "version": 2,
 "width": 300,
 "height": 400,
 "data": [{
   "name": "chart",
   "url": "tabular:///Wikimedia/CEE Spring/Statistics/MMXVI/Per country sums (general).tab",
   "format": {"type": "json", "property": "data"
   },
   "transform": [
     // Convert xField parameter into a field "_xfield"
     {"type": "formula", "field": "_xfield", "expr": 

"datum.country"

     },
     {"type": "fold", "fields": ["articles", "created", "improved"]}
   ]
 },
 {
   "name": "labels",
   "url": "tabular:///Wikimedia/CEE Spring/Statistics/MMXVI/Per country sums (general).tab",
   "format": {"type": "json", "property": "fields"}
 },
 {
   "name": "stats",
   "source": "chart",
   "transform": [{
     "type": "aggregate",
     "groupby": ["_xfield"],
     "summarize": [{"field": "value", "ops": ["sum"]}]
   }]
 }
 ],
 "scales": [
   {
     "name": "x",
     "type": "linear",
     "domain": {
       "data": "stats", "field": "sum_value"
     },
     "range": "width",


   },
   {
     "name": "y",
     "type":

"ordinal",

     "range": "height",
     "domain": {
       "data": "chart", "field": "_xfield"
     },


   },
   {
     "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"},
   }
 ],

"legends": [{

   "fill": "color",
   "stroke": "color",
   "title": "Types",
   "properties": {
     "labels": { "text": {"scale": "labels", "field": "data"} }
   }
 }],
 "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": "rect",
     "from": {
       "data": "chart",
       "transform": [
         {"type": "stack", "groupby": ["_xfield"], "sortby": ["key"], "field": "value"}
       ]
     },
     "properties": {
       "enter": {
         "y": {"scale": "y", "field": "_xfield"},
         "height": {"scale": "y", "band": true, "offset": -1},
         "x": {"scale": "x", "field": "layout_start"},
         "x2": {"scale": "x", "field": "layout_end"},
         "fill": {"scale": "color", "field": "key"}
       }
     }
   }

// Draw title at the top of the graph , {

     "type": "text",
     "properties": {
       "enter": {
         "x": {"signal": "width", "mult": 0.5, "offset": 30},
         "y": {"value": -15},
         "text": {"value": "Per country sums"},
         "fontWeight": {"value": "bold"},
         "align": {"value": "center"},
         "baseline": {"value": "bottom"},
         "fill": {"value": "#000"}
       }
     }
   }
 ]

} </graph> See or edit source data.

This graph draws one or more independent numeric data series as lines. The data must be stored on Commons' Data namespace.

Template parameters

ParameterDescriptionTypeStatus
tabletable

Data page name on Commons, without the Data: prefix. The table should contain xField column, like year or date, and one or more series columns to plot

Stringrequired
typetype

Type of the x axis - time (e.g. "2015-10" or "2013-03-08"), year (integer, but treated as a year), linear (numbers), ordinal (anything)

Default
year
Stringsuggested
xFieldxField

Id of the data column that contains values for the X axis. If type=year, xField is also "year" by default.

Stringrequired
seriesseries

List of the data columns to show as lines. Must be listed by field IDs: "field1", "field2", "field3".

Stringrequired
xZeroxZero

Force to start or not to start X axis with zero. Can be either true or false

Stringoptional
yZeroyZero

Force to start or not to start Y axis with zero. Can be either true or false

Stringoptional
xMinxMin

Force X axis to start from this value

Unknownoptional
xMaxxMax

Force X axis to end with this value

Unknownoptional
yMinyMin

Force Y axis to start from this value

Unknownoptional
yMaxyMax

Force Y axis to end with this value

Unknownoptional
titletitle

Title of the whole graph

Stringoptional
xAxisxAxis

Title of the X axis

Stringoptional
yAxisyAxis

Title of the Y axis

Stringoptional
xGridxGrid

Show grid lines for X axis

Booleanoptional
yGridyGrid

Show grid lines for Y axis

Booleanoptional
legendlegend

Title of the legend

Stringoptional
widthwidth

no description

Numberoptional
heightheight

no description

Numberoptional
debugdebug

if set, will show graph as raw JSON

Stringoptional
Edit parameter translations
<graph>
{
  //
  // ATTENTION: This code is maintained at https://www.mediawiki.org/wiki/Template:Graph:Horizontal_bars
  //            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:Graph:Horizontal_bars
  //
  // Template translation is in https://commons.wikimedia.org/wiki/Data:Original/Template:Graphs.tab
  //

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

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

    },
    "transform": [
      // Convert xField parameter into a field "_xfield"
      {"type": "formula", "field": "_xfield", "expr": 
"datum.country"
      },
      {"type": "fold", "fields": ["articles","created", "improved"]}
    ]
  },
  {
    "name": "labels",
    "url": "tabular:///{{{table}}}",
    "format": {"type": "json", "property": "fields"}
  },
  {
    "name": "stats",
    "source": "chart",
    "transform": [{
      "type": "aggregate",
      "groupby": ["_xfield"],
      "summarize": [{"field": "value", "ops": ["sum"]}]
    }]
  }
  ],
  "scales": [
    {
      "name": "x",
      "type": "linear",
      "domain": {
        "data": "stats", "field": "sum_value"
      },
      "range": "width",



    },
    {
      "name": "y",
      "type":
"ordinal",
      "range": "height",
      "domain": {
        "data": "chart", "field": "_xfield"
      },



    },
    {
      "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": "rect",
      "from": {
        "data": "chart",
        "transform": [
          {"type": "stack", "groupby": ["_xfield"], "sortby": ["key"], "field": "value"}
        ]
      },
      "properties": {
        "enter": {
          "y": {"scale": "y", "field": "_xfield"},
          "height": {"scale": "y", "band": true, "offset": -1},
          "x": {"scale": "x", "field": "layout_start"},
          "x2": {"scale": "x", "field": "layout_end"},
          "fill": {"scale": "color", "field": "key"}
        }
      }
    }


  ]
}
</graph>