react-d3 / react-d3-brush

react-d3 brush implementation
http://reactd3.org/docs/brush
12 stars 12 forks source link

Cannot read property 'scaleCategory10' of undefined #7

Closed ZakariaHili closed 7 years ago

ZakariaHili commented 7 years ago

Hi, I tried a simple example of LineBrush with data : https://github.com/react-d3/react-d3-brush/blob/master/example/src/data/user.json , but i got the error Cannot read property 'scaleCategory10' of undefined

Here the code :

var LineBrush = require('react-d3-brush').LineBrush;
import axios from "axios";
class LineTest extends React.Component {
    constructor() {
        super()
    }
    componentWillMount() {
        var chartData;
        axios.get("http://localhost:3000/TimeLine")
            .then((response) => {
                chartData = response.data;
            })
        var width = 700,
            height = 300,
            chartSeries = [
                {
                    field: 'age',
                    name: 'Age',
                    color: '#ff7f0e'
                }
            ],
            // your x accessor
            x = function (d) {
                return d.index;
            },
            brushHeight = 100;
        this.setState({
            width: width,
            height: height,
            chartSeries: chartSeries,
            x: x,
            brushHeight: brushHeight,
        })
    }
    componentDidMount() {
    }
    render() {
        return (
                        <LineBrush
                            data={this.state.chartData}
                            width={this.state.width}
                            height={this.state.height}
                            chartSeries={this.state.chartSeries}
                            x={this.state.x}
                            brushHeight={this.state.brushHeight}
                        />
        )
    }
}

Do you have any idea what i missed ? thanks in advance

ZakariaHili commented 7 years ago

I think that the pb is generated on the line var LineBrush = require('react-d3-brush').LineBrush;