Top Related Projects
Apache ECharts is a powerful, interactive charting and data visualization library for browser
Open-source JavaScript charting library behind Plotly and Dash
Bring data to life with SVG, Canvas and HTML. :bar_chart::chart_with_upwards_trend::tada:
Highcharts JS, the JavaScript charting framework
Simple HTML5 Charts using the <canvas> tag
Generation of diagrams like flowcharts or sequence diagrams from text in a similar manner as markdown
Quick Overview
S2 (Spreadsheet 2.0) is an open-source visualization library for creating interactive and customizable spreadsheets and pivot tables. It provides a powerful set of tools for data analysis, visualization, and interaction, making it easier to build complex data applications with a spreadsheet-like interface.
Pros
- Highly customizable and extensible, allowing for tailored spreadsheet experiences
- Supports various data visualization types, including charts and heatmaps
- Excellent performance, even with large datasets
- Rich set of built-in features like sorting, filtering, and cell merging
Cons
- Steeper learning curve compared to simpler spreadsheet libraries
- Documentation could be more comprehensive, especially for advanced features
- Limited community support compared to more established libraries
- Some features may require additional configuration or custom development
Code Examples
- Creating a basic S2 table:
import { TableSheet } from '@antv/s2';
const s2 = new TableSheet({
container: 'container',
data: [
{ name: 'John', age: 30, city: 'New York' },
{ name: 'Jane', age: 25, city: 'London' },
],
fields: {
columns: ['name', 'age', 'city'],
},
});
s2.render();
- Adding a custom cell renderer:
import { TableSheet, S2Event } from '@antv/s2';
const s2 = new TableSheet({
// ... configuration
});
s2.on(S2Event.DATA_CELL_RENDER, (renderInfo) => {
const { data, cellInfo } = renderInfo;
if (cellInfo.fieldValue === 'age') {
renderInfo.backgroundColor = data.age > 25 ? '#ffcccb' : '#90ee90';
}
});
s2.render();
- Implementing sorting functionality:
import { TableSheet } from '@antv/s2';
const s2 = new TableSheet({
// ... configuration
sortParams: [
{
sortFieldId: 'age',
sortMethod: 'DESC',
},
],
});
s2.render();
Getting Started
To get started with S2, follow these steps:
- Install the library:
npm install @antv/s2
- Create a container element in your HTML:
<div id="container"></div>
- Initialize and render an S2 table:
import { TableSheet } from '@antv/s2';
const s2 = new TableSheet({
container: 'container',
data: yourData,
fields: {
columns: yourColumns,
},
});
s2.render();
Competitor Comparisons
Apache ECharts is a powerful, interactive charting and data visualization library for browser
Pros of ECharts
- More comprehensive and versatile, supporting a wider range of chart types
- Larger community and ecosystem, with extensive documentation and examples
- Better performance for handling large datasets and complex visualizations
Cons of ECharts
- Steeper learning curve due to its extensive API and configuration options
- Larger file size, which may impact load times for simpler visualizations
- Less specialized for tabular data and pivot table-like structures
Code Comparison
S2 (Tabular Data Rendering):
const s2 = new PivotSheet(container, s2DataConfig, s2Options);
s2.render();
ECharts (General Chart Rendering):
const chart = echarts.init(container);
chart.setOption(chartOptions);
Key Differences
- S2 focuses on tabular data and pivot tables, while ECharts is a general-purpose charting library
- S2 provides more specialized features for data grid interactions and styling
- ECharts offers a wider range of chart types and customization options
Use Cases
- S2: Best for applications requiring interactive, spreadsheet-like data grids or pivot tables
- ECharts: Ideal for diverse data visualization needs, including complex charts and dashboards
Open-source JavaScript charting library behind Plotly and Dash
Pros of plotly.js
- Wider range of chart types and visualization options
- Extensive documentation and community support
- Built-in interactivity and responsiveness
Cons of plotly.js
- Larger file size and potentially slower performance
- Steeper learning curve for complex visualizations
- Less focused on specific data structures like pivot tables
Code Comparison
S2 (for creating a pivot table):
const s2 = new PivotSheet(container, s2DataConfig, s2Options);
s2.render();
plotly.js (for creating a basic chart):
Plotly.newPlot('myDiv', data, layout);
Both libraries offer declarative ways to create visualizations, but S2 is more specialized for tabular data, while plotly.js provides a broader range of chart types. S2's API is designed specifically for pivot tables and similar structures, whereas plotly.js offers a more general-purpose charting solution.
S2 excels in handling large datasets in tabular format, providing efficient rendering and interactions for pivot tables. plotly.js, on the other hand, shines in its versatility and ability to create a wide variety of interactive charts and plots, making it suitable for diverse data visualization needs.
Bring data to life with SVG, Canvas and HTML. :bar_chart::chart_with_upwards_trend::tada:
Pros of D3
- More versatile and flexible for creating custom visualizations
- Larger community and ecosystem with extensive documentation
- Supports a wide range of chart types and data visualization techniques
Cons of D3
- Steeper learning curve, especially for complex visualizations
- Requires more code to create basic charts compared to S2
- Less focused on specific table and spreadsheet functionality
Code Comparison
S2 (creating a basic table):
const s2 = new Sheet({
container: 'container',
data: [
{ name: 'John', age: 30 },
{ name: 'Jane', age: 25 }
],
fields: ['name', 'age']
});
D3 (creating a basic table):
const table = d3.select('#container').append('table');
const rows = table.selectAll('tr')
.data([{ name: 'John', age: 30 }, { name: 'Jane', age: 25 }])
.enter().append('tr');
rows.selectAll('td')
.data(d => Object.values(d)).enter().append('td').text(d => d);
S2 is more focused on creating tables and spreadsheets with less code, while D3 offers more flexibility but requires more code for similar tasks. D3 excels in creating custom visualizations, while S2 provides a simpler API for tabular data representation.
Highcharts JS, the JavaScript charting framework
Pros of Highcharts
- More extensive documentation and examples
- Wider range of chart types and customization options
- 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 page load times
Code Comparison
S2 example:
const s2 = new Sheet(container, dataCfg, options);
s2.render();
Highcharts example:
Highcharts.chart('container', {
series: [{
data: [1, 2, 3, 4, 5]
}]
});
Both libraries offer straightforward ways to create charts, but S2 focuses on spreadsheet-like data visualization, while Highcharts provides a more general-purpose charting solution.
S2 is designed specifically for multi-dimensional data analysis and visualization, making it more suitable for complex data grids and pivot tables. Highcharts, on the other hand, excels in creating a wide variety of chart types for different data visualization needs.
While Highcharts offers more flexibility and options, S2 provides a simpler API for specific use cases related to tabular data visualization. The choice between the two depends on the project requirements, budget constraints, and the specific types of visualizations needed.
Simple HTML5 Charts using the <canvas> tag
Pros of Chart.js
- Simpler API and easier to get started for basic charts
- Wider browser compatibility, including older versions
- Smaller file size, leading to faster load times
Cons of Chart.js
- Less customizable for complex visualizations
- Limited support for advanced data analysis features
- Fewer chart types available out-of-the-box
Code Comparison
S2 example:
const s2 = new PivotSheet(container, {
data: [{ /* data */ }],
options: {
width: 600,
height: 480,
},
});
s2.render();
Chart.js example:
const ctx = document.getElementById('myChart').getContext('2d');
const chart = new Chart(ctx, {
type: 'bar',
data: { /* data */ },
options: { /* options */ }
});
S2 focuses on pivot tables and multi-dimensional data analysis, offering more complex visualization capabilities. It provides a powerful API for customizing and interacting with data grids.
Chart.js, on the other hand, is designed for simpler, more common chart types like bar, line, and pie charts. It offers an easy-to-use API that's great for quickly creating basic charts but may be limited for more advanced use cases.
Both libraries have their strengths, and the choice between them depends on the specific requirements of your project, such as the complexity of data visualization needed and the level of customization required.
Generation of diagrams like flowcharts or sequence diagrams from text in a similar manner as markdown
Pros of Mermaid
- Simpler syntax for creating diagrams and charts
- Wider variety of diagram types (flowcharts, sequence diagrams, Gantt charts, etc.)
- Easier integration with Markdown documents
Cons of Mermaid
- Less suitable for complex data visualization and analysis
- Limited customization options for chart appearance
- Not optimized for large datasets or real-time updates
Code Comparison
Mermaid example:
graph TD
A[Start] --> B{Is it?}
B -->|Yes| C[OK]
B -->|No| D[End]
S2 example:
const s2 = new Sheet('#container', {
data: [
{ type: 'Furniture', sales: 38 },
{ type: 'Food', sales: 52 },
{ type: 'Electronics', sales: 61 }
],
fields: {
rows: ['type'],
values: ['sales']
}
});
s2.render();
While Mermaid focuses on creating simple diagrams with a text-based syntax, S2 is more suited for creating interactive and customizable data tables and charts. Mermaid is better for quick visualizations in documentation, while S2 excels in complex data analysis and presentation scenarios.
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
ç®ä½ä¸æ | English
S2
S2 æ¯ AntV å¨å¤ç»´äº¤ååæè¡¨æ ¼é¢åç解å³æ¹æ¡ï¼å®å ¨åºäºæ°æ®é©±å¨çæ¹å¼ãéè¿æä¾åºå±è½ååºï¼åºç¡ç»ä»¶ï¼ä¸å¡åºæ¯ç»ä»¶ä»¥åèªç±æ©å±çè½åï¼è®©å¼åè åºäºèªèº«åºæ¯èªç±éæ©ï¼æ¢è½å¼ç®±å³ç¨ï¼åè½èªç±åæ¥ã
ð å®ç½
⨠ç¹æ§
- å¤ç»´äº¤ååæï¼ åå«åä¸åæ维度ï¼å ¨é¢æ¥æ±ä»»æ维度çèªç±ç»ååæã
- é«æ§è½ï¼è½æ¯æå
¨éç¾ä¸æ°æ®ä¸
<8s
渲æï¼ä¹è½éè¿å±é¨ä¸é»æ¥å®ç°ç§çº§æ¸²æã - é«æ©å±æ§ï¼æ¯æä»»æçèªå®ä¹æ©å±ï¼å æ¬ä½ä¸å±éäºå¸å±ï¼æ ·å¼ï¼äº¤äºï¼æ°æ® hook æµçï¼ã
- å¼ç®±å³ç¨ï¼æä¾ä¸ååæåºæ¯ä¸å¼ç®±å³ç¨ç
React
,Vue3
çæ¬è¡¨ç»ä»¶åé å¥åæç»ä»¶ï¼åªéè¦ç®åçé ç½®å³å¯è½»æ¾å®ç°å¤æåºæ¯ç表渲æã - å¯äº¤äºï¼æ¯æ丰å¯ç交äºå½¢å¼ï¼åéãåéãè¡éãåéãå»ç»è¡å¤´ã宽é«ææ½ï¼èªå®ä¹äº¤äºçï¼
ð¦ å®è£
$ npm install @antv/s2 --save
# yarn add @antv/s2 --save
# pnpm install @antv/s2 --save
ð¨ 使ç¨
1. æ°æ®åå¤
s2DataConfig
const s2DataConfig = {
fields: {
rows: ['province', 'city'],
columns: ['type'],
values: ['price'],
},
data: [
{
province: 'æµæ±',
city: 'æå·',
type: 'ç¬',
price: '1',
},
{
province: 'æµæ±',
city: 'æå·',
type: 'çº¸å¼ ',
price: '2',
},
{
province: 'æµæ±',
city: 'èå±±',
type: 'ç¬',
price: '17',
},
{
province: 'æµæ±',
city: 'èå±±',
type: 'çº¸å¼ ',
price: '0.5',
},
{
province: 'åæ',
city: 'é¿æ¥',
type: 'ç¬',
price: '8',
},
{
province: 'åæ',
city: 'ç½å±±',
type: 'ç¬',
price: '9',
},
{
province: 'åæ',
city: 'é¿æ¥',
type: ' çº¸å¼ ',
price: '3',
},
{
province: 'åæ',
city: 'ç½å±±',
type: 'çº¸å¼ ',
price: '1',
},
],
};
2. é 置项åå¤
const s2Options = {
width: 600,
height: 600,
}
3. 渲æ
<div id="container"></div>
import { PivotSheet } from '@antv/s2';
const container = document.getElementById('container');
const s2 = new PivotSheet(container, s2DataConfig, s2Options);
s2.render();
4. ç»æ
ð¦ çæ¬
Package | Latest | Beta | Alpha | Next | Size | Download |
---|---|---|---|---|---|---|
@antv/s2 | ||||||
@antv/s2-react | ||||||
@antv/s2-vue |
ð¤ ä½è
ð¤ åä¸è´¡ç®
S2 ä½¿ç¨ pnpm ä½ä¸ºå 管çå¨
git clone git@github.com:antvis/S2.git
cd S2
# å®è£
ä¾èµ
pnpm install # æè
pnpm bootstrap
# æå
pnpm build
# è°è¯ s2-core
pnpm core:start
# è°è¯ s2-react
pnpm react:playground
# è°è¯ s2-vue
pnpm vue:playground
# åå
æµè¯
pnpm test
# 代ç é£æ ¼åç±»åæ£æµ
pnpm lint
# æ¬å°å¯å¨å®ç½
pnpm site:start
ðï¸ æ´å¯
ð§ åé¦é®é¢
æä»»ä½é®é¢è¯·ä¸¥æ ¼æç §æ¨¡ç æ交 Issue æå¨ Discussions æé®ã
ð¬ Contributors
ð License
MIT@AntV
Top Related Projects
Apache ECharts is a powerful, interactive charting and data visualization library for browser
Open-source JavaScript charting library behind Plotly and Dash
Bring data to life with SVG, Canvas and HTML. :bar_chart::chart_with_upwards_trend::tada:
Highcharts JS, the JavaScript charting framework
Simple HTML5 Charts using the <canvas> tag
Generation of diagrams like flowcharts or sequence diagrams from text in a similar manner as markdown
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