2

I am trying create a LineChart with dynamic width but only get the first value.

<LineChart data = {this.state.dataLine} options = {{}} width={this.state.widthChart} height = "250" />
2
  • Have you tried setting an inline style? facebook.github.io/react/tips/inline-styles.html Commented May 12, 2016 at 17:33
  • width is a prop of the component LineChart, the problem is the re-render when change state.... the newest LineChart have a prop redraw that trigger method destroy and re-render the chart... Commented May 13, 2016 at 12:27

1 Answer 1

1

I'm not sure how one would achieve this in react-chartjs, but it's pretty easy in react-vis, which is similar.

import React from 'react';

import {
  XAxis,
  YAxis,
  FlexibleWidthXYPlot,
  HorizontalGridLines,
  LineSeries
} from 'react-vis';

export default class Example extends React.Component {
  render() {
    return (
      <FlexibleWidthXYPlot
        height={300}>
        <HorizontalGridLines />
        <YAxis />
        <XAxis />
        <LineSeries data={myData}/>
      </FlexibleWidthXYPlot>
    );
  }
}

For more check here http://uber.github.io/react-vis/#/documentation/api-reference/flexible-plots

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.