AntV
Search…
Getting Started
Let's get started using F2!
First, we need to have a canvas in our page.
1
<canvas id="myChart"></canvas>
Copied!
Now that we have a canvas we can use, we need to include F2 in our page.
1
<!-- online -->
2
<script src="https://gw.alipayobjects.com/os/antv/assets/f2/3.2.3/f2.js"></script>
Copied!
Now, we can create a chart:
  • Instantiate the Chart class. To do this, we need to pass in the node, id, or 2d context of the canvas of where we want to draw the chart.
1
// Any of the following formats may be used, just choose one!
2
const chart = new F2.Chart({
3
id: 'myChart', // pass node's id
4
width: 375,
5
height: 260,
6
pixelRatio: window.devicePixelRatio
7
});
8
9
const chart = new F2.Chart({
10
el: document.getElementById('myChart'), // or pass node
11
width: 375,
12
height: 260,
13
pixelRatio: window.devicePixelRatio
14
});
15
16
const chart = new F2.Chart({
17
context: document.getElementById('myChart').getContext('2d'), // or pass 2d context of the canvas
18
width: 375,
19
height: 260,
20
pixelRatio: window.devicePixelRatio
21
});
Copied!
  • then relate with data. The data below shows the different types of game's sales.
1
const data = [
2
{ genre: 'Sports', sold: 275 },
3
{ genre: 'Strategy', sold: 115 },
4
{ genre: 'Action', sold: 120 },
5
{ genre: 'Shooter', sold: 350 },
6
{ genre: 'Other', sold: 150 },
7
];
8
9
chart.source(data); // load the data
Copied!
  • Draw the bar chart.
1
chart.interval().position('genre*sold').color('genre');
Copied!
  • Render! And you must call it.
1
chart.render();
Copied!
It's that easy to get started using F2! From here you can explore more options that can help you customize your charts with scales, tooltip, axis, guides, legends and much more.
There are many examples of F2 that are available in the AntV demos. You also can scan the QR code below to experience our demos on you phone.
Last modified 3yr ago
Copy link