Enable a button that hides the legend in charts

Options

by Flexmonster Pivot Table

HTML

<script src="https://cdn.flexmonster.com/flexmonster.js"></script>

<button onclick='hideLegendButton()'>Hide Legend Button</button>
<button onclick='showLegendButton()'>Show Legend Button</button>

<div id="pivot-container">The component will appear here</div>

CSS

@import url(https://cdn.flexmonster.com/assets/jsfiddle-styles.css);

JavaScript

let pivot = new Flexmonster({
  container: "pivot-container",
  componentFolder: "https://cdn.flexmonster.com/",
  toolbar: true,
  report: {
    dataSource: {
      filename: "data/data.csv"
    },
    options: {
      viewType: "charts",
      chart: {
        type: "pie",
        showLegend: true,
        showLegendButton: true
      }
    }
  }
});

function hideLegendButton() {
  let newOptions = pivot.getOptions();
  newOptions.chart.showLegendButton = false;
  pivot.setOptions(newOptions);
  pivot.refresh();
}

function showLegendButton() {
  let newOptions = pivot.getOptions();
  newOptions.chart.showLegendButton = true;
  pivot.setOptions(newOptions);
  pivot.refresh();
}