Template:Mobility: Difference between revisions
No edit summary  | 
				No edit summary Tag: Reverted  | 
				||
| Line 1: | Line 1: | ||
<noinclude>  | <noinclude>  | ||
This template dynamically generates a bar chart from the T241 data.  | |||
Usage: Insert {{Mobility}} on any page.  | |||
[[Category:Mobility]]  | |||
</noinclude>  | </noinclude>  | ||
<includeonly>  | <includeonly>  | ||
<!-- Step 1: Define an inline row formatter for each data row -->  | |||
{{#  | {{#vardefine: MobilityRowInline |  | ||
{|   | <noinclude>This block defines the JSON output for each row.</noinclude>  | ||
<includeonly>{  | |||
  "mobility": "{{{type_of_mobility}}}",  | |||
  "status": "{{{status_of_mobility_participant}}}",  | |||
  "participants": {{{participants|0}}}  | |||
}</includeonly>  | |||
}}  | |||
<!-- Step 2: Query all rows from DataSrc:T241 and output them as a raw JSON array -->  | |||
{{#vardefine:rawData|  | |||
  {{#ask:  | |||
    [[-Has subobject::DataSrc:T241]]  | |||
    | ?type_of_mobility  | |||
    | ?status_of_mobility_participant  | |||
    | ?participants  | |||
    | format=template  | |||
    | template=MobilityRowInline  | |||
    | intro=[  | |||
    | outro=]  | |||
    | sep=,  | |||
  }}  | |||
}}  | |||
<!-- Step 3: Render the chart using ECharts -->  | |||
{{#echarts:  | |||
| width=800px  | |||
| height=500px  | |||
| option = {  | |||
    tooltip: {  | |||
      trigger: 'axis',  | |||
      axisPointer: { type: 'shadow' }  | |||
    },  | |||
    legend: {},  | |||
    dataset: [  | |||
      {  | |||
        id: 'raw',  | |||
        dimensions: ['mobility','status','participants'],  | |||
        source: {{#var:rawData}}  | |||
      },  | |||
      {  | |||
        id: 'Student bachelor',  | |||
        fromDatasetId: 'raw',  | |||
        transform: {  | |||
          type: 'filter',  | |||
          config: { dimension: 'status', '=': 'Student bachelor' }  | |||
        }  | |||
      },  | |||
      {  | |||
        id: 'Student master',  | |||
        fromDatasetId: 'raw',  | |||
        transform: {  | |||
          type: 'filter',  | |||
          config: { dimension: 'status', '=': 'Student master' }  | |||
        }  | |||
      },  | |||
      {  | |||
        id: 'Student doctorate',  | |||
        fromDatasetId: 'raw',  | |||
        transform: {  | |||
          type: 'filter',  | |||
          config: { dimension: 'status', '=': 'Student doctorate' }  | |||
        }  | |||
      },  | |||
      {  | |||
        id: 'Staff academic',  | |||
        fromDatasetId: 'raw',  | |||
        transform: {  | |||
          type: 'filter',  | |||
          config: { dimension: 'status', '=': 'Staff academic' }  | |||
        }  | |||
      },  | |||
      {  | |||
        id: 'Staff administrative',  | |||
        fromDatasetId: 'raw',  | |||
        transform: {  | |||
          type: 'filter',  | |||
          config: { dimension: 'status', '=': 'Staff administrative' }  | |||
        }  | |||
      },  | |||
      {  | |||
        id: 'Researcher',  | |||
        fromDatasetId: 'raw',  | |||
        transform: {  | |||
          type: 'filter',  | |||
          config: { dimension: 'status', '=': 'Researcher' }  | |||
        }  | |||
      }  | |||
    ],  | |||
    xAxis: {  | |||
      type: 'category'  | |||
    },  | |||
    yAxis: {  | |||
      type: 'value'  | |||
    },  | |||
    series: [  | |||
      {  | |||
        name: 'Student bachelor',  | |||
        type: 'bar',  | |||
        datasetId: 'Student bachelor',  | |||
        encode: { x: 'mobility', y: 'participants' }  | |||
      },  | |||
      {  | |||
        name: 'Student master',  | |||
        type: 'bar',  | |||
        datasetId: 'Student master',  | |||
        encode: { x: 'mobility', y: 'participants' }  | |||
      },  | |||
      {  | |||
        name: 'Student doctorate',  | |||
        type: 'bar',  | |||
        datasetId: 'Student doctorate',  | |||
        encode: { x: 'mobility', y: 'participants' }  | |||
      },  | |||
      {  | |||
        name: 'Staff academic',  | |||
        type: 'bar',  | |||
        datasetId: 'Staff academic',  | |||
        encode: { x: 'mobility', y: 'participants' }  | |||
      },  | |||
      {  | |||
        name: 'Staff administrative',  | |||
        type: 'bar',  | |||
        datasetId: 'Staff administrative',  | |||
        encode: { x: 'mobility', y: 'participants' }  | |||
      },  | |||
      {  | |||
        name: 'Researcher',  | |||
        type: 'bar',  | |||
        datasetId: 'Researcher',  | |||
        encode: { x: 'mobility', y: 'participants' }  | |||
      }  | |||
    ]  | |||
  }  | |||
}}  | |||
</includeonly>  | </includeonly>  | ||
Revision as of 10:33, 20 March 2025
This template dynamically generates a bar chart from the T241 data. Usage: Insert
on any page.
}}
</includeonly>