Top Related Projects
Simple HTML5 Charts using the <canvas> tag
Bring data to life with SVG, Canvas and HTML. :bar_chart::chart_with_upwards_trend::tada:
JavaScript 3D Library.
Open-source JavaScript charting library behind Plotly and Dash
📊 Interactive JavaScript Charts built on SVG
Highcharts JS, the JavaScript charting framework
Quick Overview
F2 is a lightweight and high-performance charting library for mobile applications. It's designed to work efficiently on mobile devices, providing interactive and customizable charts with a small footprint. F2 is part of the AntV data visualization ecosystem developed by Ant Financial.
Pros
- Optimized for mobile performance with a small file size
- Supports a wide range of chart types and customizations
- Provides smooth animations and interactions
- Offers a flexible and extensible plugin system
Cons
- Primarily focused on mobile, may not be the best choice for desktop applications
- Learning curve might be steeper compared to simpler charting libraries
- Documentation and community resources are not as extensive as some more popular libraries
Code Examples
Creating a basic line chart:
import F2 from '@antv/f2';
const chart = new F2.Chart({
id: 'myChart',
pixelRatio: window.devicePixelRatio
});
chart.source(data);
chart.line().position('year*value');
chart.render();
Adding interactivity with tooltips:
import F2 from '@antv/f2';
const chart = new F2.Chart({
id: 'myChart',
pixelRatio: window.devicePixelRatio
});
chart.source(data);
chart.tooltip({
showCrosshairs: true,
showItemMarker: false,
onShow: function(ev) {
const { items } = ev;
items[0].name = null;
items[0].value = '$ ' + items[0].value;
}
});
chart.line().position('date*value');
chart.render();
Creating a custom shape:
import F2 from '@antv/f2';
F2.Shape.registerShape('point', 'custom', {
draw(cfg, container) {
const point = cfg.points[0];
const group = container.addGroup();
group.addShape('circle', {
attrs: {
x: point.x,
y: point.y,
r: 5,
fill: cfg.color
}
});
return group;
}
});
const chart = new F2.Chart({ id: 'myChart' });
chart.source(data);
chart.point().position('x*y').shape('custom');
chart.render();
Getting Started
To use F2 in your project, first install it via npm:
npm install @antv/f2
Then, import and use it in your JavaScript file:
import F2 from '@antv/f2';
const data = [
{ year: '1951', sales: 38 },
{ year: '1952', sales: 52 },
{ year: '1953', sales: 61 },
{ year: '1954', sales: 145 },
{ year: '1955', sales: 48 },
{ year: '1956', sales: 38 },
{ year: '1957', sales: 38 },
{ year: '1958', sales: 38 },
];
const chart = new F2.Chart({
id: 'myChart',
pixelRatio: window.devicePixelRatio
});
chart.source(data);
chart.interval().position('year*sales');
chart.render();
Make sure to have a canvas element with the id 'myChart' in your HTML file where the chart will be rendered.
Competitor Comparisons
Simple HTML5 Charts using the <canvas> tag
Pros of Chart.js
- Wider community support and more extensive documentation
- Broader range of chart types and customization options
- Better suited for complex, interactive visualizations
Cons of Chart.js
- Larger file size, which may impact load times for mobile applications
- Steeper learning curve for beginners due to more advanced features
Code Comparison
F2:
import F2 from '@antv/f2';
const chart = new F2.Chart({
id: 'myChart',
pixelRatio: window.devicePixelRatio
});
Chart.js:
import Chart from 'chart.js/auto';
const ctx = document.getElementById('myChart');
const chart = new Chart(ctx, {
type: 'bar',
data: chartData
});
Both libraries offer straightforward initialization, but F2 is more focused on mobile-specific features like pixel ratio adjustment. Chart.js provides a more familiar API for web developers and offers built-in chart types.
F2 excels in creating lightweight, performant charts for mobile devices, while Chart.js is more versatile for various web applications. F2's smaller file size and mobile-first approach make it ideal for projects prioritizing performance on mobile devices. Chart.js, with its extensive feature set and plugin ecosystem, is better suited for complex data visualizations across different platforms.
Bring data to life with SVG, Canvas and HTML. :bar_chart::chart_with_upwards_trend::tada:
Pros of D3
- More powerful and flexible for creating complex, interactive visualizations
- Larger ecosystem with extensive documentation and community support
- Supports a wider range of chart types and custom visualizations
Cons of D3
- Steeper learning curve, especially for beginners
- Requires more code to create basic charts
- Performance can be an issue with large datasets
Code Comparison
F2 example:
chart.interval().position('genre*sold').color('genre');
chart.render();
D3 example:
svg.selectAll("rect")
.data(data)
.enter()
.append("rect")
.attr("x", (d, i) => i * 70)
.attr("y", d => height - 10 * d)
.attr("width", 65)
.attr("height", d => d * 10)
.attr("fill", "green");
F2 is more concise for simple charts, while D3 offers more granular control but requires more code. F2 is designed for mobile-first scenarios and performs well on mobile devices, whereas D3 is more versatile but may require additional optimization for mobile use. F2 has a smaller file size and faster rendering speed for basic charts, making it suitable for projects with performance constraints.
JavaScript 3D Library.
Pros of three.js
- Powerful 3D rendering capabilities for complex scenes and animations
- Extensive documentation and large community support
- Wide range of features including physics, VR, and post-processing effects
Cons of three.js
- Steeper learning curve due to its complexity and 3D focus
- Larger file size and potentially higher performance overhead
- May be overkill for simple 2D visualizations
Code Comparison
three.js (3D scene creation):
const scene = new THREE.Scene();
const camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0.1, 1000);
const renderer = new THREE.WebGLRenderer();
renderer.setSize(window.innerWidth, window.innerHeight);
document.body.appendChild(renderer.domElement);
F2 (2D chart creation):
const chart = new F2.Chart({
id: 'myChart',
pixelRatio: window.devicePixelRatio
});
chart.source(data);
chart.interval().position('genre*sold').color('genre');
chart.render();
Summary
Three.js is a powerful 3D graphics library with extensive features, while F2 focuses on lightweight 2D visualizations for mobile devices. Three.js offers more complex rendering capabilities but comes with a steeper learning curve and larger file size. F2 is more suitable for simple, performance-optimized 2D charts on mobile platforms. The choice between them depends on the specific requirements of your project, whether you need 3D capabilities, and your target devices.
Open-source JavaScript charting library behind Plotly and Dash
Pros of plotly.js
- More comprehensive and feature-rich, supporting a wider range of chart types and advanced visualizations
- Extensive documentation and community support, making it easier for developers to find solutions and resources
- Better suited for complex, interactive data visualizations and dashboards
Cons of plotly.js
- Larger file size and potentially slower performance, especially for simpler charts or mobile applications
- Steeper learning curve due to its extensive API and numerous configuration options
- May be overkill for projects that only require basic charting functionality
Code Comparison
F2 example:
import F2 from '@antv/f2';
const chart = new F2.Chart({
id: 'myChart',
pixelRatio: window.devicePixelRatio
});
chart.source(data);
chart.interval().position('genre*sold').color('genre');
chart.render();
plotly.js example:
import Plotly from 'plotly.js-dist';
Plotly.newPlot('myDiv', [{
x: ['genre1', 'genre2', 'genre3'],
y: [20, 14, 23],
type: 'bar'
}], {
title: 'Sales by Genre'
});
Both libraries offer straightforward ways to create charts, but F2 focuses on mobile-first, lightweight charting, while plotly.js provides more extensive options for complex visualizations.
📊 Interactive JavaScript Charts built on SVG
Pros of ApexCharts.js
- More extensive chart types and customization options
- Better documentation and examples
- Larger community and more frequent updates
Cons of ApexCharts.js
- Larger file size, potentially impacting load times
- Steeper learning curve due to more complex API
- May be overkill for simple charting needs
Code Comparison
F2:
import { Chart } from '@antv/f2';
const chart = new Chart({
id: 'myChart',
pixelRatio: window.devicePixelRatio
});
chart.line().position('x*y').color('type');
chart.render();
ApexCharts.js:
import ApexCharts from 'apexcharts';
const options = {
chart: { type: 'line' },
series: [{ data: [30, 40, 35, 50, 49, 60, 70] }],
xaxis: { categories: [1991, 1992, 1993, 1994, 1995, 1996, 1997] }
};
const chart = new ApexCharts(document.querySelector("#chart"), options);
chart.render();
Both libraries offer straightforward ways to create charts, but ApexCharts.js requires more configuration upfront. F2 has a more concise syntax for basic charts, while ApexCharts.js provides more detailed control over chart appearance and behavior.
Highcharts JS, the JavaScript charting framework
Pros of Highcharts
- More extensive feature set and chart types
- Better support for complex, interactive visualizations
- Larger community and ecosystem
Cons of Highcharts
- Commercial license required for most use cases
- Steeper learning curve due to more complex API
- Larger file size, potentially impacting performance
Code Comparison
F2 example:
import { Chart } from '@antv/f2';
const chart = new Chart({
container: 'mountNode',
width: 400,
height: 300
});
chart.line().position('x*y').color('type');
chart.render();
Highcharts example:
Highcharts.chart('container', {
series: [{
type: 'line',
data: [1, 2, 3, 4, 5]
}]
});
Key Differences
- F2 is designed for mobile-first scenarios, while Highcharts is more versatile
- F2 uses a declarative API, Highcharts uses a configuration object approach
- F2 is open-source and free, Highcharts requires a license for commercial use
- Highcharts offers more out-of-the-box features, while F2 focuses on performance and simplicity
Both libraries have their strengths, with F2 excelling in mobile and lightweight scenarios, and Highcharts offering more comprehensive charting capabilities for complex visualizations.
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual CopilotREADME
F2ï¼ä¸ä¸ªä¸æ³¨äºç§»å¨ï¼å¼ç®±å³ç¨çå¯è§å解å³æ¹æ¡ï¼å®ç¾æ¯æ H5 ç¯å¢åæ¶å ¼å®¹å¤ç§ç¯å¢ï¼node, å°ç¨åºï¼weexï¼ãå®å¤çå¾å½¢è¯æ³ç论ï¼æ»¡è¶³ä½ çåç§å¯è§åéæ±ãä¸ä¸ç移å¨è®¾è®¡æå¼ä¸ºä½ 带æ¥æä½³ç移å¨ç«¯å¾è¡¨ä½éªãè±æ README
å¨æ¤è¡·å¿æè°¢ãThe Grammar of Graphicsãçä½è Leland Wilkinsonï¼ä¸º F2 çå¾å½¢è¯æ³æä¾äºç论åºç¡ï¼
å®è£
$ npm install @antv/f2
ç¹æ§
ä¸æ³¨ç§»å¨ï¼ä½éªä¼é
-
è½»éååç°ï¼èªç¶åé¦ï¼å¨è®¾è®¡ä¸æ们以人为æ¬ï¼è¿½æ±èªç¶ç®åææï¼æå¸å¼åç表达ææï¼è®©ç¨æ·å¨ç¢çåçæ¶é´éæ´å¿«æ´é«æå¾è·åå¾è¡¨ä¿¡æ¯ãåæ¶å¨å¯è§åçæä½æ们追æ±å 容åæä½ææºèåï¼ç¬¦å人çèªç¶è¡ä¸ºååºï¼è®©äº¤äºæä½æ´èªç¶ã
-
轻巧æµç ï¼F2 ä¸ç´è´åäºè¿½æ±æè´çæ§è½ï¼é对移å¨è®¾å¤åäºå¤§éçä¼åï¼å¨æ¯æ丰å¯ï¼50+ï¼å¾è¡¨çåºç¡ä¸åæ¶ä¿æ代ç éçå°å·§ï¼ä¸å¸¦äº¤äºçæ¬ gzip å缩å 44kï¼å¸¦ææ交äºçæ¬ 56kï¼ï¼åæ¶æä¾æ¨¡ååç设计以æ¯æå¨æå è½½ï¼æä¾æ´ä¼ç大å°ã
-
å¤ç«¯å¼æï¼å¨å®ç¾æ¯æ H5 ç¯å¢çåæ¶ï¼åæ¶å ¼å®¹ Node.jsï¼æ¯ä»å®å°ç¨åºã微信å°ç¨åºãReact Native以å Weex 端ç渲æï¼ä¸ä»½ä»£ç ï¼å¤è®¾å¤å¤ç¯å¢æ¸²æã
å¾è¡¨ä¸°å¯ï¼ç»ä»¶å®å¤
ä¸ä¼ ç»çå¾è¡¨åºä¸åï¼æå¼äºç¹å¾ç¹åçå°è£ æè·¯ï¼åºäºå¼ºå¤§çå¾å½¢è¯æ³ç论ï¼ä»¥æ°æ®é©±å¨ï¼éè¿å¾å½¢è¯æ³çç»åçµæ´»æ建åç±»å¾è¡¨ï¼ç®åå¯ç»å¶ 50+ å¾è¡¨ç±»åï¼å½ç¶ï¼è¿å¯ä»¥æ´å¤ï¼ï¼è¦çåç±»åºæ¯å¨æä¾åºç¡çå¾è¡¨å¯è§åè½åå¤ï¼æ们è¿æä¾äºä¸°å¯å¾è¡¨åè½ç»ä»¶ï¼æ»¡è¶³åç§åè½éæ±ã
æ©å±çµæ´»ï¼åææ é
æ们å¨æä¾æä½³å®è·µçåæ¶ï¼è¿ä¸ºå¼åè æä¾äºçµæ´»çæ©å±æºå¶ï¼å æ¬ Shapeãå¨ç»ä»¥å交äºçèªå®ä¹è½åï¼å½ç¶è¿æå¾è¡¨æ ·å¼ç个æ§åå®å¶ï¼æ»¡è¶³åç§ä¸ªæ§åçå¾è¡¨è¦æ±ã
ææ¡£
å¿«éå¼å§
<canvas id="mountNode"></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 },
];
// è·å canvas context
const context = document.getElementById('mountNode').getContext('2d');
const { props } = (
<Canvas context={context} pixelRatio={window.devicePixelRatio}>
<Chart data={data}>
<Axis field="genre" />
<Axis field="sold" />
<Interval x="genre" y="sold" color="genre" />
<Tooltip />
</Chart>
</Canvas>
);
const canvas = new Canvas(props);
canvas.render();
æ´å¤ç¤ºä¾ï¼demosã
ææºæ«ç è§ç demos
æ¬å°å¼å
$ npm install
# å
åå§å monorepo
$ npm run bootstrap
# åè·æµè¯ç¨ä¾
$ npm run test
# çå¬æ件ååæ建ï¼å¹¶æå¼ demo 页é¢
$ npm run dev
# æå¼æä¸ä¸ªå
·ä½çæµè¯ç¨ä¾
$ npm run test-watch -- 'TestFileName'
å¦ä½è´¡ç®
å¦ææ¨å¨ä½¿ç¨çè¿ç¨ä¸ç¢°å°é®é¢ï¼å¯ä»¥å éè¿ issues ççæ没æ类似ç bug æè 建议ã
å¦éæ交代ç ï¼è¯·éµä»æ们çè´¡ç®æåã
ä½éªæ¹è¿è®¡å说æ
F2 ä» 3.1.12ï¼2018-06-20 åå¸ï¼çæ¬å¼å§æ·»å äºF2.trackï¼trueï¼
æ¹æ³ã ç®åæ们çä½éªæ¹è¿è®¡åå·²ç»å®æï¼æä»¥ä» 3.3.4 çæ¬å¼å§è¯¥æ¹æ³å°ä» F2 ä¸å é¤ã å¦æå®ç»ä½ 带æ¥éº»ç¦ï¼æ们深表ææã
License
Top Related Projects
Simple HTML5 Charts using the <canvas> tag
Bring data to life with SVG, Canvas and HTML. :bar_chart::chart_with_upwards_trend::tada:
JavaScript 3D Library.
Open-source JavaScript charting library behind Plotly and Dash
📊 Interactive JavaScript Charts built on SVG
Highcharts JS, the JavaScript charting framework
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual Copilot