Skip to content

Instantly share code, notes, and snippets.

@lucguillemot
Created May 9, 2019 14:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lucguillemot/8d264884740607bfe68c7898d8a02ccf to your computer and use it in GitHub Desktop.
Save lucguillemot/8d264884740607bfe68c7898d8a02ccf to your computer and use it in GitHub Desktop.
import * as React from "react";
import * as vega from "vega";
export const Chart = ({ spec, handleClick }) => {
const chartContainer = React.useRef();
React.useEffect(() => {
const createView = async () => {
try {
const view = new vega.View(vega.parse(spec), {
logLevel: vega.Warn,
renderer: "svg",
container: chartContainer.current,
hover: true
});
const awaitedView = await view.runAsync();
awaitedView.addSignalListener("clickOnCategory", handleClick);
} catch (error) {
console.log(error);
}
};
createView();
}, [spec, handleClick]);
return <div ref={chartContainer} />;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment