Wikipedia:Graphics Lab/Resources/Charts

mw:Extension:Chart is being rolled out across some WMF wikis, with the aim of replacing the now deprecated mw:Extension:Graph. This page seeks to collate information on when, how and with what standards to create charts in articles on the English Wikipedia.

When a chart is appropriate

[edit]

On Wikipedia, charts serve to present data in a manner that is both informative and accessible. Often, including raw data tables is not only impractical, but also contributes little to the reader's understanding. Charts should only be used when they demonstrably improve a reader's understanding of a topic. The appropriateness of a chart is up to an editor's discretion, though graphs should not be used purely to illustrate an article or fill areas that lack sutiable media.

When not to use a chart

[edit]
  • Where prose is written around (or heavily with reference to) the contents of a chart, it is better to either not include it at all or integrate statistics into the prose from a reliable source.
  • To replace a data table. Whilst data tables may be problematic, replacing them solely with charts has other issues (for example, sources may be more difficult to find).

How to create chart

[edit]
[edit]

Moving data to Commons

[edit]

Creating a chart

[edit]

Charts are stored on Wikimedia Commons in the Data namespace. The chart is split into two pages, a page ending with .tab for the datapoints and a page ending with .chart for the layout.

Multiple language fields: Description and title can be in several languages. In order to add a language add an aditional line with the correct language code. Format: "langcode": "text". Use a comma after each entry except for the last one.

All of the comments should be deleted by the chart extension on save.

Tab page

[edit]
{
    "license": "CC-BY-SA-4.0", // the licence you want to have your chart under. If transferred from wikipedia, it is best to use CC-BY-SA-4.0 to match Wikipedia's licence
    "description": {
        "en": "Graph of numbers", // Description of your chart. Is not displayed on your chart. Can be in several languages.
    },
    "sources": "from example.com", // The website you got the datapoints from
    "schema": {
        "fields": [
            { // x field
                "name": "a1", // only relevant for internal use
                "type": "number", // type of the field, expected data type of values. Can be string or number.
                "title": {
                    "en": "Date" // title for this field, used in the legend.
                }
            },
            { // y field
                "name": "a2", // only relevant for internal use
                "type": "number", // type of the field, expected data type of values. Can be string or number.
                "title": {
                    "en": "Values" // title for this field, used in the legend.
                }
            }  // we can continue after this with more fields. Above is just enough to have x and y.
        ]
    },
    "data": [
        [  // the number of data in each group here needs to match the number of fields. Since we have two fields, x and y, there are two numbers.
            1000, // x value
            100 // y value
        ] // this is just one x,y point, add more as needed.
    ]
}

Chart page

[edit]
{
    "license": "CC-BY-SA-4.0", // licence of the chart
    "version": 1, // version number. Used to identify what version of the chart definition the chart complies with. Is 1 for now, as no newer version exists.
    "type": "line", // type of chart. Can be bar, rect, line, area or pie. If the chart is simple enough, changing this is enough to go between chart types.
    "source": "Graph.tab", // the name of the associated tab page
    "transform": { // only used in transforms
        "module": "Module name", // name of the module to use, without namespace.
        "function": "main", // the name of the function to use, within the module.
        "args": {
            "id": "Q123" // an argument that will be passed on to the module. "id" is the argument and "Q123" is an example of the value expected.
        }
    },
    "xAxis": {
        "title": {
            "en": "Year" // title of the x axis, displayed horizontally and centered on the axis. Can be in several languages.
        },
        "format": "none" // format of the xAxis. This can be either none or auto. Auto is used if it is okay to truncate the values, like 2000 to 2k. Since we are using years here the answer is no and none is used.
    },
    "yAxis": {
        "title": {
            "en": "Values" // title of the y axis, displayed vertically and centered on the axis. Can be in several languages.
        }
    },
    "title": {
        "en": "Annual data" // title of the chart, displayed at the top. Can be in several languages.
    },
    "categories": "Charts of the United Kingdom" // the category the chart page is in. Charts of country is commonly used.
}

Placing chart on-Wiki

[edit]

Bar chart

[edit]

Line chart

[edit]

Other good practices in chart creation

[edit]

Migrating existing charts

[edit]

See also

[edit]

Notes

[edit]