antvis/G2







Do you want to work on this issue?
You can request for a bounty in order to promote it!
官网示例 API 和 Spec 互转 #6420
lxfu1 posted onGitHub
AntV Open Source Contribution Plan(可选)
- 我同意将这个 Issue 参与 OSCP 计划
Issue 类型
高级任务
任务介绍
提供一个脚本、工具或者浏览器插件,支持官网 API 和 Spec 模式代码互转(API 转 Spec 优先级高)。
API
import { Chart } from '@antv/g2';
const data = [
{ year: '1951 年', sales: 38 },
{ year: '1952 年', sales: 52 },
{ year: '1956 年', sales: 61 },
{ year: '1957 年', sales: 145 },
{ year: '1958 年', sales: 48 },
{ year: '1959 年', sales: 38 },
{ year: '1960 年', sales: 38 },
{ year: '1962 年', sales: 38 },
];
const chart = new Chart({
container: 'container',
autoFit: true,
});
chart
.interval()
.coordinate({ transform: [{ type: 'transpose' }] })
.data(data)
.encode('x', 'year')
.encode('y', 'sales');
chart.render();
Spec
import { Chart } from "@antv/g2";
const chart = new Chart({ container: "container" });
chart.options({
type: "interval",
autoFit: true,
data: [
{ year: "1951 年", sales: 38 },
{ year: "1952 年", sales: 52 },
{ year: "1956 年", sales: 61 },
{ year: "1957 年", sales: 145 },
{ year: "1958 年", sales: 48 },
{ year: "1959 年", sales: 38 },
{ year: "1960 年", sales: 38 },
{ year: "1962 年", sales: 38 },
],
encode: { x: "year", y: "sales" },
coordinate: { transform: [{ type: "transpose" }] },
});
chart.render();
参考说明
No response