Skip to content

0.1.0

Choose a tag to compare

@pearmini pearmini released this 23 Nov 09:28
· 4 commits to main since this release

Hello World

Install via a package manager such as Yarn or NPM.

$ npm install @berryv/g2-ssr-node

Use CLI to convert a G2 specification file named in bar.json into a png file named bar.png.

$ g2-ssr-node g2png -i ./bar.json -o bar.png

In Node, use render to convert a G2 specification into a png file named bar.png.

const fs = require("fs");
const { render } = require("@berry/g2-ssr-node");

const spec = {
  type: "interval",
  data: [
    { genre: "Sports", sold: 275 },
    { genre: "Strategy", sold: 115 },
    { genre: "Action", sold: 120 },
    { genre: "Shooter", sold: 350 },
    { genre: "Other", sold: 150 },
  ],
  encode: { x: "genre", y: "sold", color: "genre" },
};

render(spec).then((canvas) => {
  const out = fs.createWriteStream("./bar.png");
  const stream = canvas.createJPEGStream();
  stream.pipe(out);
  stream.on("finish", () => console.log("Convert successfully!"));
});