我正在开发反应应用程序,我使用反应谷歌图表来显示带有注释的折线图。但是我遇到了折线图中列的角色属性问题,已经在工作组件中导入了 react-google-charts。下面是我的代码:
Home.tsx > 组件
import * as React from 'react';
import { Chart } from 'react-google-charts';
import GoogleDataTableColumnRoleType from 'react-google-charts/dist/types';
export class Home extends React.Component<IChildComponentProps,AddDataState> {
constructor(props) {
super(props);
public render() {
<div id="chart_div2">
<Chart
width={400}
height={'300px'}
chartType="LineChart"
loader={<div>Loading Chart</div>}
rows={this.state.o3TargetChart}
columns={[
{
type: "string",
label: "Week"
},
{
type: "number",
label: "O3Done"
},
{
type: "string",
role: GoogleDataTableColumnRoleType.annotation // getting error here
},
{
type: "number",
label: "Target"
}
]}
options={{
title: '',
hAxis: {
title: 'Week', titleTextStyle: {
},
baselineColor: '#cccccc'
},
vAxis: {
title: 'O3 Coverage ( in %)', minValue: 0, maxValue: 100, titleTextStyle: {
},
baselineColor: '#cccccc',
},
pointsVisible: true,
chartArea: {
left: 100
},
height: 400,
width: 1000,
}}
/>
</div>
}
}
虽然我可以在 node_modules 目录下找到类型模块,如下所示:
node_modules\react-google-charts\dist\types.d.ts
已经按照其他人的建议在 webpack.config.js 文件中添加了以下代码:
resolve: {
extensions: ['', '.js', '.jsx']
},
我仍然收到模块未找到错误。请建议..