referenceError: Can't find variable in react-native with fetch

referenceError: Can't find variable in react-native with fetch

嘿,我正在尝试使用来自在线数据 json 反应本机数据的胜利来制作图表。该组件的代码如下所示

export default class Dashboard extends Component {
  static navigationOption = {
    title: 'DashboardScreen'
  }

state = {
      getValue: '',
      dataSource:[],
      isLoading: true
    }


  componentDidMount() {
   
    const url = 'myurl';
    fetch(url, {
      method: 'GET',
      headers: new Headers({
        'Content-Type' : 'application/json',
      })
    })
    .then((response)=> response.json() )
    .then((responseJson) => {
      console.log(responseJson.Views)
      this.setState({
        dataSource: responseJson,
        isLoading: false
      })
    })
    .catch((Error) => {
      console.log(Error)
    })


  }

  render() {
      return(
          <View style = {styles.container}>
              <VictoryChart minDomain={{ y: 0, x:0 }} width={350} theme={VictoryTheme.material}>
                <VictoryBar
                    style={{
                      data: { stroke: "#c43a31" },
                      parent: { border: "1px solid #ccc"}
                    }}
                    data={[
                      { x: 1, y: 1 },
                      { x: 2, y: dataSource[0].views},
                      { x: 3, y: dataSource[1].views},
                      { x: 4, y: dataSource[2].views},
                      { x: 5, y: dataSource[3].views}
                      ]}> 
                </VictoryBar>
              </VictoryChart>
          </View>
      )
  }
  }

我认为获取已经使 json 信息成为 dataSource 变量中的一个数组,并且可以在胜利中用作数据,但我总是遇到像 referenceError: Can't find variable 'dataSource' 这样的错误

所以,如果有人能帮助我解决这段代码并建议如何将 json 数据制作成图表,那就太好了

变化:

  data={[
                      { x: 1, y: 1 },
                      { x: 2, y: dataSource[0].views},
                      { x: 3, y: dataSource[1].views},
                      { x: 4, y: dataSource[2].views},
                      { x: 5, y: dataSource[3].views}
                      ]}> 

  data={[
                      { x: 1, y: 1 },
                      { x: 2, y: this.state.dataSource[0].views},
                      { x: 3, y: this.state.dataSource[1].views},
                      { x: 4, y: this.state.dataSource[2].views},
                      { x: 5, y: this.state.dataSource[3].views}
                      ]}> 

希望对您有所帮助!