https://www.yuque.com/antv/f2/getting-startedhtml
https://antv.alipay.com/zh-cn/f2/3.x/demo/index.htmlnpm
npm install @antv/f2 --save
// import 或 require const F2 = require('@antv/f2');
<canvas id="myChart" width="400" height="260"></canvas>
// F2 對數據源格式的要求,僅僅是 JSON 數組,數組的每一個元素是一個標準 JSON 對象。 const data = [ { genre: 'Sports', sold: 275 }, { genre: 'Strategy', sold: 115 }, { genre: 'Action', sold: 120 }, { genre: 'Shooter', sold: 350 }, { genre: 'Other', sold: 150 }, ]; // Step 1: 建立 Chart 對象 const chart = new F2.Chart({ id: 'myChart', pixelRatio: window.devicePixelRatio // 指定分辨率 }); // Step 2: 載入數據源 chart.source(data); // Step 3:建立圖形語法,繪製柱狀圖,由 genre 和 sold 兩個屬性決定圖形位置,genre 映射至 x 軸,sold 映射至 y 軸 chart.interval().position('genre*sold').color('genre'); // Step 4: 渲染圖表 chart.render();
const data = [ { genre: 'Sports', sold: 275 }, { genre: 'Strategy', sold: 115 }, { genre: 'Action', sold: 120 }, { genre: 'Shooter', sold: 350 }, { genre: 'Other', sold: 150 }, ]; const chart = new F2.Chart({ id: 'myChart', pixelRatio: window.devicePixelRatio // 指定分辨率 }); // load the data chart.source(data); // draw a column chart chart.interval().position('genre*sold').color('genre'); chart.render();