问题
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