Published
Edited
Mar 20, 2020
2 forks
141 stars
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
G2Demo1 = {
// for Observable Cell
const wrapper = html`<div style="text-align: center;"></div>`;
const container = html`<div></div>`
wrapper.appendChild(container);
yield wrapper;

// Demo Code
const data = [
{ genre: 'Sports', sold: 275 },
{ genre: 'Strategy', sold: 115 },
{ genre: 'Action', sold: 120 },
{ genre: 'Shooter', sold: 350 },
{ genre: 'Other', sold: 150 },
];

// Step 1: declare Chart instance
const chart = new G2.Chart({
container, // specify DOM element
width: 600,
height: 300,
});

// Step 2: load data
chart.data(data);

// Step 3: grammar of graphics
chart.interval().position('genre*sold');

// Step 4: render
chart.render();
}
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
G2PlotDemo = {
// for Observable Cell
const wrapper = html`<div style="text-align: center;"></div>`;
const container = html`<div style="height: 600px;"></div>`
wrapper.appendChild(container);
yield wrapper;
// Demo Code
const data = [
{ type: 'Apple', value: 27 },
{ type: 'Banana', value: 25 },
{ type: 'Orange', value: 18 },
{ type: 'Peach', value: 15 },
{ type: 'Other', value: 8 },
];

const rosePlot = new G2Plot.Rose(container, {
forceFit: true,
title: { visible: true, text: 'A Basic Rose Chart' },
description: { visible: true, text: 'Declare (colorField) as the field maps to color channel.' },
radius: 0.8,
data,
radiusField: 'value',
categoryField: 'type',
colorField: 'type',
label: { visible: true, type: 'outer', content: (text) => text.value },
});

rosePlot.render();
}
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell

One platform to build and deploy the best data apps

Experiment and prototype by building visualizations in live JavaScript notebooks. Collaborate with your team and decide which concepts to build out.
Use Observable Framework to build data apps locally. Use data loaders to build in any language or library, including Python, SQL, and R.
Seamlessly deploy to Observable. Test before you ship, use automatic deploy-on-commit, and ensure your projects are always up-to-date.
Learn more