Show only the lowest expanded field on the chart

Options

by Flexmonster Pivot Table

HTML

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

<div>
  <h2>Show only the lowest expanded field on the chart</h2>
  <p>
    Using the buttons below, you can turn on/off the
    <a
      href="https://www.flexmonster.com/api/chart-options-object/#onelevel"
      target="_blank"
    >chart.oneLevel</a> option. See the difference in behavior by expanding
    and collapsing fields with the <code>+</code>/<code>-</code> icons 
    on the chart's legend.
  </p>
</div>

<button onclick="showOneLevel(true)">Show the lowest expanded field</button>
<button onclick="showOneLevel(false)">Show all fields</button>

<div id="pivot-container"></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/",
  report: {
    dataSource: {
      filename: "data/data.csv"
    },
    options: {
      viewType: "charts",
      chart: {
        type: "pie"
      }
    },
    slice: {
      rows: [
        { 
        	uniqueName: "Country",
          filter: {
          	members: ["Canada", "Germany", "United Kingdom"]
          }
        }, 
        { 
        	uniqueName: "Category",
          filter: {
          	members: ["Accessories", "Bikes", "Clothing"]
          }
        },
        {	uniqueName: "Color" }
      ],
      columns: [{ uniqueName: "[Measures]" }],
      measures: [{ uniqueName: "Price" }],
    }
  }
});

function showOneLevel(value) {
  pivot.setOptions({
    chart: {
      oneLevel: value
    }
  });
  pivot.refresh();
}