வார்ப்புரு:Graph:Stacked
&lt;includeonly&gt;{{safesubst:#tag:templatestyles||src=&quot;Graph:Chart/styles.css&quot;}}{{#tag:graph|
 {
   //
   // ATTENTION: This code is maintained at https://www.mediawiki.org/wiki/Template:Graph:Stacked
   //            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:Stacked
   //
   // Template translation is in https://commons.wikimedia.org/wiki/Data:Original/Template:Graphs.tab
   //
 
   &quot;version&quot;: 2,
   &quot;width&quot;: {{{width|550}}},
   &quot;height&quot;: {{{height|250}}},
 
   &quot;data&quot;: [{
     &quot;name&quot;: &quot;chart&quot;,
 
 {{#switch: {{{tabletype|tab}}}
 |tab=    &quot;url&quot;: &quot;tabular:///{{{table}}}&quot;,
 |query=  &quot;url&quot;: &quot;wikidatasparql:///?query={{urlencode:{{{table}}}|PATH}}&quot;,
 }}
     &quot;format&quot;: {&quot;type&quot;: &quot;json&quot;
 {{#ifeq:{{{tabletype|tab}}}|tab|
       , &quot;property&quot;: &quot;data&quot;
 }}
 {{#ifeq:{{{type|}}}|time|
       , &quot;parse&quot;: {&quot;{{{xField}}}&quot;: &quot;date&quot;}
 }}
     },
     &quot;transform&quot;: [
       // Convert xField parameter into a field &quot;_xfield&quot;
       {&quot;type&quot;: &quot;formula&quot;, &quot;field&quot;: &quot;_xfield&quot;, &quot;expr&quot;:
 {{#switch: {{{type|}}}
 | year= &quot;datetime(datum.{{{xField|year}}}, 0, 1)&quot;
 | &quot;datum.{{{xField}}}&quot;
 }}
       },
       {&quot;type&quot;: &quot;sort&quot;, &quot;by&quot;: [&quot;_xfield&quot;]},
 {{#if:{{{series|}}}
 |     {&quot;type&quot;: &quot;fold&quot;, &quot;fields&quot;: [{{{series}}}]},
 }}
       // For non-bar graph, ensure that all missing values still present as zeros to avoid area breaks
       // We might need to allow other, non-0 values to be imputed.
 {{#if:{{{barwidth|}}}||
       {
         &quot;type&quot;: &quot;impute&quot;,
         &quot;groupby&quot;: [&quot;{{{group|key}}}&quot;],
         &quot;orderby&quot;: [&quot;_xfield&quot;],
         &quot;field&quot;: &quot;{{{value|value}}}&quot;,
         &quot;method&quot;: &quot;value&quot;,
         &quot;value&quot;: 0
       },
 }}
     ]
   },
 {{#if:{{{series|}}}|{{#ifeq: {{{tabletype|tab}}} | tab |
   {
     &quot;name&quot;: &quot;labels&quot;,
     &quot;url&quot;: &quot;tabular:///{{{table}}}&quot;,
     &quot;format&quot;: {&quot;type&quot;: &quot;json&quot;, &quot;property&quot;: &quot;fields&quot;}
   },
 }}}}
   {
     &quot;name&quot;: &quot;stats&quot;,
     &quot;source&quot;: &quot;chart&quot;,
     &quot;transform&quot;: [{
       &quot;type&quot;: &quot;aggregate&quot;,
       &quot;groupby&quot;: [&quot;_xfield&quot;],
       &quot;summarize&quot;: [{&quot;field&quot;: &quot;{{{value|value}}}&quot;, &quot;ops&quot;: [&quot;sum&quot;]}]
     }]
   }
   ],
   &quot;scales&quot;: [
     {
       &quot;name&quot;: &quot;x&quot;,
       &quot;type&quot;: {{#switch: {{{type|}}}
 | year= &quot;time&quot;
 | &quot;{{{type}}}&quot;
 }},
       &quot;domain&quot;: {&quot;data&quot;: &quot;chart&quot;, &quot;field&quot;: &quot;_xfield&quot;},
 {{#if:{{{barwidth|}}}|{{#ifeq:{{{type|}}}|ordinal|&quot;points&quot;: true,}}}}
       &quot;range&quot;: &quot;width&quot;,
 {{#if:{{{xZero|}}}|&quot;zero&quot;: {{{xZero}}},}}
 {{#if:{{{xMin|}}}|&quot;domainMin&quot;: {{{xMin}}},}}
 {{#if:{{{xMax|}}}|&quot;domainMax&quot;: {{{xMax}}},}}
     },
     {
       &quot;name&quot;: &quot;y&quot;,
       &quot;type&quot;: &quot;linear&quot;,
       &quot;range&quot;: &quot;height&quot;,
       &quot;domain&quot;: {&quot;data&quot;: &quot;stats&quot;, &quot;field&quot;: &quot;sum_{{{value|value}}}&quot;},
 {{#if:{{{yZero|}}}|&quot;zero&quot;: {{{yZero}}},}}
 {{#if:{{{yMin|}}}|&quot;domainMin&quot;: {{{yMin}}},}}
 {{#if:{{{yMax|}}}|&quot;domainMax&quot;: {{{yMax}}},}}
     },
     {
       &quot;name&quot;: &quot;color&quot;,
       &quot;type&quot;: &quot;ordinal&quot;,
       &quot;domain&quot;: {&quot;data&quot;: &quot;chart&quot;, &quot;field&quot;: &quot;{{{group|key}}}&quot;},
       &quot;range&quot;: {{{colors|&quot;category10&quot;}}}
     },
 {{#if:{{{series|}}}|
     {
       &quot;name&quot;: &quot;labels&quot;,
       &quot;type&quot;: &quot;ordinal&quot;,
 {{#ifeq: {{{tabletype|tab}}} | tab
 |     &quot;domain&quot;: {&quot;data&quot;: &quot;labels&quot;, &quot;field&quot;: &quot;name&quot;},
       &quot;range&quot;: {&quot;data&quot;: &quot;labels&quot;, &quot;field&quot;: &quot;title&quot;},
 |     &quot;domain&quot;: [{{{series|}}}],
       &quot;range&quot;: [{{{series|}}}],
 }}
     }
 }}
   ],
 {{#if:{{{legend|}}}|
   &quot;legends&quot;: [{
     &quot;fill&quot;: &quot;color&quot;,
     &quot;stroke&quot;: &quot;color&quot;,
 {{#ifeq: {{{legend|}}}|-|| &quot;title&quot;: &quot;{{{legend|}}}&quot;, }}
 {{#if:{{{series|}}}
 |   &quot;properties&quot;: { &quot;labels&quot;: { &quot;text&quot;: {&quot;scale&quot;: &quot;labels&quot;, &quot;field&quot;: &quot;data&quot;} } }
 }}
   }],
 }}
   &quot;axes&quot;: [
     {&quot;scale&quot;: &quot;x&quot;, &quot;type&quot;: &quot;x&quot;, &quot;tickSizeEnd&quot;: 0
 {{#ifeq:{{{xTicks|7}}}|-||, &quot;ticks&quot;: {{{xTicks|7}}}}}
 {{#if:{{{xAxis|}}}|, &quot;title&quot;: &quot;{{{xAxis}}}&quot;}}
 {{#if:{{{xGrid|}}}|, &quot;grid&quot;: true}}
 },
     {&quot;scale&quot;: &quot;y&quot;, &quot;type&quot;: &quot;y&quot;, &quot;tickSizeEnd&quot;: 0
 // When drawing &quot;type=year&quot; bars with the given width, shift y axis left by half the width
 {{#ifeq:{{{type|}}}|year|{{#ifeq:{{{barwidth|auto}}}|auto||,&quot;offset&quot;:{{#expr:1+{{{barwidth}}}/2}}}}}}
 {{#ifeq:{{{yTicks|-}}}|-||, &quot;ticks&quot;: {{{yTicks}}}}}
 {{#if:{{{yAxis|}}}|, &quot;title&quot;: &quot;{{{yAxis}}}&quot;}}
 {{#if:{{{yGrid|}}}|, &quot;grid&quot;: true}}
 }
   ],
 
   &quot;marks&quot;: [
     // Group data by the &quot;key&quot;, and draw lines, one line per key
     {
 {{#if:{{{barwidth|}}}
 |     &quot;type&quot;: &quot;rect&quot;,
       &quot;from&quot;: {
         &quot;data&quot;: &quot;chart&quot;,
         &quot;transform&quot;: [
           {&quot;type&quot;: &quot;stack&quot;, &quot;groupby&quot;: [&quot;_xfield&quot;], &quot;sortby&quot;: [&quot;{{{group|key}}}&quot;], &quot;field&quot;: &quot;{{{value|value}}}&quot;}
         ]
       },
       &quot;properties&quot;: {
         &quot;enter&quot;: {
           &quot;x&quot;: {&quot;scale&quot;: &quot;x&quot;, &quot;field&quot;: &quot;_xfield&quot;
 // When drawing &quot;type=year&quot; bars with the given width, shift them back by half the width
 {{#ifeq:{{{type|}}}|year|{{#ifeq:{{{barwidth|auto}}}|auto||,&quot;offset&quot;:{{#expr:{{{barwidth}}}/-2}}}}}}
           },
 {{#ifeq:{{{barwidth|}}}|auto|
   {{#ifeq:{{{type|}}}|ordinal
 |         &quot;width&quot;: {&quot;scale&quot;: &quot;x&quot;, &quot;band&quot;: true, &quot;offset&quot;: -1},
 |         &quot;width&quot;: {&quot;value&quot;: 3},
   }}
 |         &quot;width&quot;: {&quot;value&quot;: {{{barwidth}}} },
 }}
           &quot;y&quot;: {&quot;scale&quot;: &quot;y&quot;, &quot;field&quot;: &quot;layout_start&quot;},
           &quot;y2&quot;: {&quot;scale&quot;: &quot;y&quot;, &quot;field&quot;: &quot;layout_end&quot;},
           &quot;fill&quot;: {&quot;scale&quot;: &quot;color&quot;, &quot;field&quot;: &quot;{{{group|key}}}&quot;}
         }
       }
 |     &quot;type&quot;: &quot;group&quot;,
       &quot;from&quot;: {
         &quot;data&quot;: &quot;chart&quot;,
         &quot;transform&quot;: [
           {&quot;type&quot;: &quot;stack&quot;, &quot;groupby&quot;: [&quot;_xfield&quot;], &quot;sortby&quot;: [&quot;{{{group|key}}}&quot;], &quot;field&quot;: &quot;{{{value|value}}}&quot;},
           {&quot;type&quot;: &quot;facet&quot;, &quot;groupby&quot;: [&quot;{{{group|key}}}&quot;]}
         ]
       },
       &quot;marks&quot;: [
         {
           &quot;type&quot;: &quot;area&quot;,
           &quot;properties&quot;: {
             &quot;enter&quot;: {
               &quot;x&quot;: {&quot;scale&quot;: &quot;x&quot;, &quot;field&quot;: &quot;_xfield&quot;},
               &quot;y&quot;: {&quot;scale&quot;: &quot;y&quot;, &quot;field&quot;: &quot;layout_start&quot;},
               &quot;y2&quot;: {&quot;scale&quot;: &quot;y&quot;, &quot;field&quot;: &quot;layout_end&quot;},
               &quot;fill&quot;: {&quot;scale&quot;: &quot;color&quot;, &quot;field&quot;: &quot;{{{group|key}}}&quot;},
               &quot;interpolate&quot;: {&quot;value&quot;: &quot;monotone&quot;}
             }
           }
         }
       ],
 }}
     }
 
 {{#if:{{{title|}}}|
     // Draw title at the top of the graph
 ,   {
       &quot;type&quot;: &quot;text&quot;,
       &quot;properties&quot;: {
         &quot;enter&quot;: {
           &quot;x&quot;: {&quot;signal&quot;: &quot;width&quot;, &quot;mult&quot;: 0.5, &quot;offset&quot;: 30},
           &quot;y&quot;: {&quot;value&quot;: -15},
           &quot;text&quot;: {&quot;value&quot;: &quot;{{{title}}}&quot;},
           &quot;fontWeight&quot;: {&quot;value&quot;: &quot;bold&quot;},
           &quot;align&quot;: {&quot;value&quot;: &quot;center&quot;},
           &quot;baseline&quot;: {&quot;value&quot;: &quot;bottom&quot;},
           &quot;fill&quot;: {&quot;value&quot;: &quot;#000&quot;}
         }
       }
     }
 }}
   ]
 }
 }}
 &lt;small&gt;{{#switch: {{{tabletype|tab}}}
 |tab= {{#invoke:TNT|msg|Original/Template:Graphs.tab|source-table|{{#invoke:TNT|link|{{{table}}}}}}}.
 |query= {{#invoke:TNT|msg|Original/Template:Graphs.tab|source-wdqs|https://query.wikidata.org/#{{urlencode:{{{table}}}|PATH}}}}.
 }}&lt;/small&gt;