一旦我将Fusioncharts中的图表添加为新的依赖项,并尝试启动应用程序,它将引发以下错误并中止
ReferenceError:未定义窗口 从node_modules / react-fusioncharts / lib / ReactFC.js:13:21
行开始这整个代码都在client / imports / ui / pages下,所以我不明白为什么要尝试寻找窗口对象,而在流星开始时也是如此!
代码段。
std::variant
答案 0 :(得分:0)
要使用FusionCharts渲染图表,您需要先导入FusionCharts库,然后再导入要尝试从中渲染图表包的库文件,然后可以导入react-fusioncharts插件,下面是您的代码段参考
import React from 'react';
import ReactDOM from 'react-dom';
import FusionCharts from 'fusioncharts';
import Charts from 'fusioncharts/fusioncharts.charts';
import ReactFC from 'react-fusioncharts';
import FusionTheme from 'fusioncharts/themes/fusioncharts.theme.fusion';
ReactFC.fcRoot(FusionCharts, Charts, FusionTheme);
const myDataSource = {
"chart": {
"caption": "Countries With Most Oil Reserves [2017-18]",
"subCaption": "In MMbbl = One Million barrels",
"xAxisName": "Country",
"yAxisName": "Reserves (MMbbl)",
"numberSuffix": "K",
"theme": "fusion"
},
"data": [
{
"label": "Venezuela",
"value": "290"
},
{
"label": "Saudi",
"value": "260"
},
{
"label": "Canada",
"value": "180"
},
{
"label": "Iran",
"value": "140"
},
{
"label": "Russia",
"value": "115"
},
{
"label": "UAE",
"value": "100"
},
{
"label": "US",
"value": "30"
},
{
"label": "China",
"value": "30"
}
]
};
const chartConfigs = {
type: 'column2d',
width: 600,
height: 400,
dataFormat: 'json',
dataSource: myDataSource,
};
ReactDOM.render(
<ReactFC {...chartConfigs} />,
document.getElementById('root'),
);