Socket
Socket
Sign inDemoInstall

@antv/g2

Package Overview
Dependencies
22
Maintainers
0
Versions
366
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

@antv/g2


Version published
Weekly downloads
124K
decreased by-16.88%
Maintainers
0
Created
Weekly downloads
 

Package description

What is @antv/g2?

@antv/g2 is a powerful and flexible data visualization library for creating a wide range of charts and graphs. It is designed to be highly customizable and supports a variety of chart types, including bar charts, line charts, pie charts, and more. The library is built on top of the AntV visualization ecosystem and provides a declarative syntax for defining visualizations.

What are @antv/g2's main functionalities?

Bar Chart

This code creates a simple bar chart using the @antv/g2 library. It defines a dataset and uses the `interval` geometry to create bars representing the data.

const { Chart } = require('@antv/g2');
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 Chart({ container: 'container', autoFit: true, height: 500 });
chart.data(data);
chart.interval().position('genre*sold');
chart.render();

Line Chart

This code creates a line chart using the @antv/g2 library. It defines a dataset and uses the `line` geometry to create a line representing the data over time.

const { Chart } = require('@antv/g2');
const data = [
  { year: '1991', value: 3 },
  { year: '1992', value: 4 },
  { year: '1993', value: 3.5 },
  { year: '1994', value: 5 },
  { year: '1995', value: 4.9 },
  { year: '1996', value: 6 },
  { year: '1997', value: 7 },
  { year: '1998', value: 9 },
  { year: '1999', value: 13 }
];
const chart = new Chart({ container: 'container', autoFit: true, height: 500 });
chart.data(data);
chart.scale({ year: { range: [0, 1] }, value: { min: 0 } });
chart.line().position('year*value');
chart.render();

Pie Chart

This code creates a pie chart using the @antv/g2 library. It defines a dataset and uses the `interval` geometry with a `theta` coordinate to create slices representing the data.

const { Chart } = require('@antv/g2');
const data = [
  { item: 'A', count: 40 },
  { item: 'B', count: 21 },
  { item: 'C', count: 17 },
  { item: 'D', count: 13 },
  { item: 'E', count: 9 }
];
const chart = new Chart({ container: 'container', autoFit: true, height: 500 });
chart.data(data);
chart.coordinate('theta', { radius: 0.75 });
chart.interval().position('count').color('item').adjust('stack');
chart.render();

Other packages similar to @antv/g2

Readme

Source

English | 简体中文

G2 5.0

G2 is a visualization grammar for dashboard building, data exploration and storytelling.

Build Status Coverage Status npm Version npm Download npm License

examples

G2 is named after Leland Wilkinson’s book The Grammar of Graphics and was profoundly inspired by it in the very beginning. Here are some resources you can begin with:

  • Introduction - a brief overview and G2's motivations
  • Examples - a large number of demos to learn from and copy-paste
  • Tutorials - interactive case-driven guides of G2's core concepts
  • API Reference - complete documentation for all visualization components

✨ Features

  • Progressive Usage - The main objective of G2 is to help you get meaningful visualizations quickly with concise declarations and it infers the rest. But you can configure much more for complex and advanced situations.
  • Declarative API - We employs a functional declarative API to specify chart options in a programmatic fashion, which contributes to better logic reuse and more flexible code organization.
  • High Extensibility - To satisfy specific needs, G2 provides a convenient and consistent mechanism to extend everything you can imagine, whether a scale, a transform, a mark, etc,. You can even customize a brand new visualization tool based on this mechanism.
  • Comprehensive Grammar - G2 rejects a chart typology in favor of marks, transforms, scales, coordinates, and compositions. In addition to static visual representations, it's possible to declare data-driven animations and apply well-designed action-based interactions to plots as well.
  • Powerful Renderer - There is a powerful renderer G under G2 to generate web-based visualizations using Canvas, SVG or WebGL. The plenty of plugins it has benefit G2 from rendering charts with novel styles such as hand-drawn and fully embracing the ecosystem of D3.

🔨 Getting Started

G2 is usually installed via a package manager such as npm or Yarn.

$ npm install @antv/g2
$ yarn add @antv/g2

The Chart object then can be imported from G2.

<div id="container"></div>
import { Chart } from '@antv/g2';

// A tabular data to be visualized.
const data = [
  { genre: 'Sports', sold: 275 },
  { genre: 'Strategy', sold: 115 },
  { genre: 'Action', sold: 120 },
  { genre: 'Shooter', sold: 350 },
  { genre: 'Other', sold: 150 },
];

// Instantiate a new chart.
const chart = new Chart({
  container: 'container',
});

// Specify visualization.
chart
  .interval()                   // Create an interval mark and add it to the chart.
  .data(data)                   // Bind data for this mark.
  .encode('x', 'genre')         // Assign genre column to x position channel.
  .encode('y', 'sold')          // Assign sold column to y position channel.
  .encode('color', 'genre');    // Assign genre column to color channel.

// Render visualization.
chart.render();

If all goes well, you can get the following lovely bar chart!

example

🌍 Ecosystem

📮 Contributing

code

📄 License

MIT@AntV.

Keywords

FAQs

Last updated on 28 Jun 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc