Created
May 9, 2019 14:08
-
-
Save lucguillemot/8d264884740607bfe68c7898d8a02ccf to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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