question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

unable to resize chat after update dom with chartjs 2.7

See original GitHub issue

It works on chartjs 2.6 but DOSE NOT on 2.7.

Could you fix this?

Here is my js code.

class DataSet extends React.Component {
  ...

  const data = {
   labels = ["aaa", "bbb", "ccc"];
   datasets = [
     { label: "xxxx", backgroundColor: "xxx", data: [...], ... },
     { label: "yyyy", backgroundColor: "yyy", data: [...], ... },
     { label: "xxxx", backgroundColor: "xxx", data: [...], ... },
   ]
  }

  const options = {
    responsive: true,
    ...
  }

  render() {
    return(<PowerMonitorGraph data={data} options={options} />)
  }
}

class PowerMonitorGraph extends React.Component {
  constructor(props) {
    super(props);
    this.state = {
      data: this.props.data,
      options: this.props.options
    }
  }

  componentWillReceiveProps(props) {
    if (props.data !== this.state.data) {
      this.setState({data: props.data});
    }
    if (props.options !== this.state.options) {
      this.setState({options: props.options});
    }
  }

  render() {
    return (
      <Line data={this.props.data} options={this.props.options} redraw={true}/>
    )
  }
}

And then here is debug.

After first rending,it works fine.

<div class="chartjs-size-monitor" style="position: absolute; left: 0px; top: 0px; right: 0px; bottom: 0px; overflow: hidden; pointer-events: none; visibility: hidden; z-index: -1;">
  <div class="chartjs-size-monitor-expand" style="position:absolute;left:0;top:0;right:0;bottom:0;overflow:hidden;pointer-events:none;visibility:hidden;z-index:-1;">
    <div style="position:absolute;width:1000000px;height:1000000px;left:0;top:0"></div>
  </div>
  <div class="chartjs-size-monitor-shrink" style="position:absolute;left:0;top:0;right:0;bottom:0;overflow:hidden;pointer-events:none;visibility:hidden;z-index:-1;">
    <div style="position:absolute;width:200%;height:200%;left:0; top:0"></div>
  </div>
</div>
<canvas height="422" width="844" class="chartjs-render-monitor" style="display: block; width: 844px; height: 422px;"></canvas>

After update dom, resize does’t work.

<canvas height="422" width="844" class="chartjs-render-monitor" style="display: block; width: 844px; height: 422px;"></canvas>

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:8
  • Comments:6

github_iconTop GitHub Comments

1reaction
jegherscommented, Nov 14, 2017

I have a similar problem, chart will resize it’s width, but the height will never change. Is there ANY example showing how to make a chart resize properly when it’s parent resizes?

0reactions
ptuxcommented, Aug 16, 2018

I do not care about this anymore. so, I close this.

Read more comments on GitHub >

github_iconTop Results From Across the Web

unable to resize chat after update dom with chartjs 2.7 #203
I have a similar problem, chart will resize it's width, but the height will never change. Is there ANY example showing how to...
Read more >
Developers - unable to resize chat after update dom with chartjs 2.7 -
Coming soon: A brand new website interface for an even better experience!
Read more >
Chart.js Disappear on Window Resize - Stack Overflow
I had a problem, on resizing the window, the graph disappears. I solved the problem by creating the graph just once with the...
Read more >
Chart.js
js-based, charting libraries that render as SVG. Canvas rendering makes Chart.js very performant, especially for large datasets and complex ...
Read more >
Responsive Charts - Chart.js
js is unable to properly resize for the print layout. To work around this, you can pass an explicit size to .resize() then...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found