ReactJs HighCharts toggle table and chart not updating

只愿长相守 提交于 2019-12-24 20:32:25

问题


I want to display table and its chart using toggle button. Default it should disply chart, when I click button, it should change to table view. On first click it works but doesn't work from second click.

I have created the codesandbox project. CodeSandbox

What mistake have I done in this code.


回答1:


Dynamic change of the showTable option does not change the display of the table. You need to toggle the containers visibility:

Highcharts.Chart.prototype.viewData = function () {
  $(this.renderTo).toggle();
  if (!this.insertedTable) {
    var div = document.createElement('div');
    div.className = 'highcharts-data-table';
    // Insert after the chart container
    this.renderTo.parentNode.insertBefore(div, this.renderTo.nextSibling);
    div.innerHTML = this.getTable();
    this.insertedTable = true;
    div.id = this.container.id + '-data-table';
  } else {
    $('#' + this.container.id + '-data-table').toggle();
  }
};

Live demo: https://codesandbox.io/s/l4x11ykm67

API Reference: https://api.highcharts.com/highcharts/exporting.showTable



来源:https://stackoverflow.com/questions/55069255/reactjs-highcharts-toggle-table-and-chart-not-updating

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!