I draw a graph by using react vega. When i write config for the graph it works. I would like to get config in json format from an external file barChartConfig.json
I try to import this file but did not work. My question is how can i import a json and assign it into a variable?
import config from './barChartConfig.json';
const barSpec = config;
const Vega = ReactVega.default;
class App extends React.Component {
constructor(props) {
super(props);
this.state = {
spec: barSpec
// ,data: barData
};
}
render() {
return (
<div>
<Vega spec={this.state.spec} />
</div>
);
}
}
const app = document.getElementById('app');
ReactDOM.render(<App />, app);
If you are using create-react-app,
json-loader
will be already included. In that case you can use the following statement to load json file.