2017-05-30 53 views
0

我想使用react-d3-components來顯示一些數據。我試着這樣做:React D3線圖組件執行錯誤

import React from 'react' 
import ChartState from './chart-state' 
import LineChart from 'react-d3-components' 

class ChartWidget extends React.Component { 
    constructor() { 
    super(...arguments) 
    this.state = new ChartState() 
} 

render() { 
    return (
    <Chart state={this.state} /> 
    ) 
    } 
} 

const Chart = observer (({ state, data }) => (
<div> 
    <LineChart 
     data={state.data} 
     width={400} 
     height={400} 
     margin={{top: 10, bottom: 50, left: 50, right: 10}}/> 
</div> 
)) 

export default ChartWidget 

但是,這並不工作,我得到的錯誤React.createElement: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: undefined. You likely forgot to export your component from the file it's defined in. Check the render method of _class .

有誰知道我做錯了什麼?

+0

您是否嘗試將'export default Chart'添加到代碼的末尾? – Sventies

+0

@SventenHaaf是的,我仍然同樣的問題:-( – Steve

回答

0

我想通了自己:

import { LineChart } from 'react-d3-components' 

是解決方案!