ReactJs HighCharts toggle table and chart not upda

2019-08-20 00:42发布

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条回答
再贱就再见
2楼-- · 2019-08-20 01:37

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

查看更多
登录 后发表回答