css Audio - Active file-generic CSS - Active Generic - Active HTML - Active JS - Active SVG - Active Text - Active file-generic Video - Active header Love html icon-new-collection icon-person icon-team numbered-list123 pop-out spinner split-screen star tv

Pen Settings

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

Code Indentation

     

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

HTML Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

            
              <html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width,height=device-height">
    <title>台灣老年人口與長照機構供需比</title>
    <style>::-webkit-scrollbar{display:none;}html,body{overflow:hidden;height:100%;}</style>
</head>
<body>
  <button onclick="changeData('all')">All Data</button>
  <button onclick="changeData()">Remove 外島</button>
<div id="mountNode"></div>
<script src="https://gw.alipayobjects.com/os/antv/assets/g2/3.0.9/g2.min.js"></script>
  <script src="https://gw.alipayobjects.com/os/antv/assets/data-set/0.8.7/data-set.min.js"></script>
</body>
</html>

            
          
!
            
              var imageMap = {
  '長照、養護人員': 'https://image.flaticon.com/icons/svg/65/65463.svg',
  '老年人口數(85~100+)': 'https://image.flaticon.com/icons/svg/773/773256.svg',
  '可供進住人數': 'https://image.flaticon.com/icons/svg/73/73784.svg',
};

// const allData = [ { name: '可供進住人數',
//     '新北市': 10629,
//     '臺北市': 5521,
//     '桃園市': 3345,
//     '臺中市': 4185,
//     '臺南市': 5490,
//     '高雄市': 7971,
//     '宜蘭縣': 2374,
//     '新竹縣': 1283,
//     '苗栗縣': 943,
//     '彰化縣': 2655,
//     '南投縣': 1243,
//     '雲林縣': 2001,
//     '嘉義縣': 1293,
//     '屏東縣': 3036,
//     '臺東縣': 730,
//     '花蓮縣': 879,
//     '澎湖縣': 83,
//     '基隆市': 1908,
//     '新竹市': 439,
//     '嘉義市': 811,
//     '金門縣': 294,
//     '連江縣': 34 },
//   { name: '長照、養護人員',
//     '新北市': 3828,
//     '臺北市': 2097,
//     '桃園市': 1121,
//     '臺中市': 1304,
//     '臺南市': 1726,
//     '高雄市': 2666,
//     '宜蘭縣': 851,
//     '新竹縣': 378,
//     '苗栗縣': 273,
//     '彰化縣': 874,
//     '南投縣': 333,
//     '雲林縣': 734,
//     '嘉義縣': 417,
//     '屏東縣': 866,
//     '臺東縣': 222,
//     '花蓮縣': 260,
//     '澎湖縣': 23,
//     '基隆市': 560,
//     '新竹市': 159,
//     '嘉義市': 299,
//     '金門縣': 58,
//     '連江縣': 15 },
//   { name: '老年人口數(85~100+)',
//     '新北市': 48056,
//     '臺北市': 56730,
//     '桃園市': 28271,
//     '臺中市': 32844,
//     '臺南市': 31438,
//     '高雄市': 37454,
//     '宜蘭縣': 8525,
//     '新竹縣': 8471,
//     '苗栗縣': 11315,
//     '彰化縣': 22824,
//     '南投縣': 10194,
//     '雲林縣': 14894,
//     '嘉義縣': 12527,
//     '屏東縣': 13650,
//     '臺東縣': 4156,
//     '花蓮縣': 6041,
//     '澎湖縣': 2438,
//     '基隆市': 6038,
//     '新竹市': 6352,
//     '嘉義市': 4339,
//     '金門縣': 2026,
//     '連江縣': 174 } ];
const data = [ { name: '可供進住人數',
    '北部': 25499,
    '中部': 11027,
    '南部': 18684,
    '東部': 1609,
    '外島': 328 },
  { name: '長照、養護人員',
    '北部': 8994,
    '中部': 3518,
    '南部': 5997,
    '東部': 482,
    '外島': 73 },
  { name: '老年人口數(85~100+)',
    '北部': 162443,
    '中部': 92071,
    '南部': 101846,
    '東部': 10197,
    '外島': 2200 } ];
// const SimpleAll = [
//   {name: '可供進住人數', value: 57147},
//   {name: '長照、養護人員', value: 19064},
//   {name: '老年人口數(85~100+)', value: 368757}
// ];
  const ds = new DataSet();
  const dv = ds.createView().source(data);
  dv.transform({
    type: 'fold',
    fields: [ '北部', '中部', '南部', '東部', '外島'], // 展開資料
    key: '區域', // key
    value: '區域人數', // value
    retains: [ 'name' ]
  });

  const chart = new G2.Chart({
    container: 'mountNode',
    forceFit: true,
    height: window.innerHeight
  });
  chart.source(dv);
  chart.interval().position('區域*區域人數').color('name').adjust([{
    type: 'dodge',
    marginRatio: 1 / 5
  }]);

  chart.scale('區域人數', {
    minLimit: 73
  });

  chart.point()
    .position(['區域', '區域人數'])
    .adjust([{
      type: 'dodge',
      marginRatio: 1 / 5
    }])
    .size(25)
    .shape('name', function (name) {
    return ['image', imageMap[name]];
  });
  chart.render();

const changeData = (status) => {
  chart.filter('區域', val => {
    if (status === 'all') {
      chart.scale('區域人數', {
        minLimit: 73
      });
      return true;
    }
    chart.scale('區域人數', {
      minLimit: 400
    });
    return val !== '外島';
  });
  chart.repaint();
};
            
          
!
999px
🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.
Loading ..................

Console