FlexPie 101

This page shows how to get started with Wijmo's FlexPie control.

Getting Started

Steps for getting started with the FlexPie control in JavaScript applications:

  1. Add references to Wijmo.
  2. Add markup to serve as the Wijmo control's host.
  3. Initialize the Wijmo control(s) via JavaScript.
  4. (Optional) Add some CSS to customize the input control's appearance.
<div id="introChart"></div>
var introChart = new wijmo.chart.FlexPie('#introChart', { binding: 'value', bindingName: 'name', itemsSource: getData() });

Result (live):

Basic Features

The FlexPie control has five basic properties that allow you to customize its layout and appearance:

The example below allows you to see what happens when you change these properties. Notice that clicking on a pie slice will display a tooltip for the data point.

<div id="basicChart"></div> <div class="form-horizontal"> <div class="form-group"> <label class="col-md-3 control-label">Inner Radius</label> <div class="col-md-9"> <input id="basicInnerRadius" type="text" /> </div> </div> <div class="form-group"> <label class="col-md-3 control-label">Offset</label> <div class="col-md-9"> <input id="basicOffset" type="text" /> </div> </div> <div class="form-group"> <label class="col-md-3 control-label">Start Angle</label> <div class="col-md-9"> <input id="basicStartAngle" type="text" /> </div> </div> <div class="form-group"> <div class="col-md-offset-3 col-md-9"> <div id="basicPalette"></div> </div> </div> <div class="form-group"> <div class="col-md-offset-3 col-md-9"> <div class="checkbox"> <label> <input id="basicReversed" type="checkbox" /> Reversed </label> </div> </div> </div> </div>
var basicChart = new wijmo.chart.FlexPie('#basicChart', { binding: 'value', bindingName: 'name', itemsSource: getData() }); // change the pie properties var innerRadius = new wijmo.input.InputNumber('#basicInnerRadius', { min: 0, max: 1, step: 0.1, format: 'n1', valueChanged: function (s, e) { if (s.value >= s.min && s.value <= s.max) { basicChart.innerRadius = s.value; } } }); var offset = new wijmo.input.InputNumber('#basicOffset', { min: 0, max: 1, step: 0.1, format: 'n1', valueChanged: function (s, e) { if (s.value >= s.min && s.value <= s.max) { basicChart.offset = s.value; } } }); var startAngle = new wijmo.input.InputNumber('#basicStartAngle', { min: -360, max: 360, step: 45, format: 'n0', valueChanged: function (s, e) { if (s.value >= s.min && s.value <= s.max) { basicChart.startAngle = s.value; } } }); var palettes = new wijmo.input.Menu('#basicPalette', { itemsSource: 'standard,cocoa,coral,dark,highcontrast,light,midnight,modern,organic,slate,zen,cyborg,superhero,flatly,darkly,cerulan'.split(','), itemClicked: function (s, e) { basicChart.palette = wijmo.chart.Palettes[s.text]; updateMenuHeader(s, 'Palette'); } }); updateMenuHeader(palettes, 'Palette'); document.getElementById('basicReversed').addEventListener('click', function (e) { basicChart.reversed = e.target.checked; });

Result (live):

Legend and Titles

The legend properties can be used to customize the appearance of the chart's legend. The header and footer properties can be used to add titles to the FlexPie control as well.

The following example allows you to change the FlexPie's legend.position, header, and footer properties in real-time.

<div id="ltChart"></div> <div class="form-horizontal"> <div class="form-group"> <label class="col-md-3 control-label">Header</label> <div class="col-md-9"> <input id="ltHeader" type="text" class="form-control" placeholder="Specify the FlexPie's header" /> </div> </div> <div class="form-group"> <label class="col-md-3 control-label">Footer</label> <div class="col-md-9"> <input id="ltFooter" type="text" class="form-control" placeholder="Specify the FlexPie's footer" /> </div> </div> <div class="form-group"> <div class="col-md-offset-3 col-md-9"> <select id="ltLegPos"> <option value="None">None</option> <option value="Left">Left</option> <option value="Top">Top</option> <option value="Right">Right</option> <option value="Bottom">Bottom</option> </select> </div> </div> </div>
var ltChart = new wijmo.chart.FlexPie('#ltChart', { itemsSource: getData(), binding: 'value', bindingName: 'name', header: 'Fruit By Value', footer: '(c) ' + new Date().getFullYear() + ' GrapeCity, inc.' }); // header input var header = document.getElementById('ltHeader'); header.value = ltChart.header; header.addEventListener('input', function (e) { ltChart.header = e.target.value; }); // footer input var footer = document.getElementById('ltFooter'); footer.value = ltChart.footer; footer.addEventListener('input', function (e) { ltChart.footer = e.target.value; }); // legend position var ltLegPos = new wijmo.input.Menu('#ltLegPos', { itemClicked: function (s, e) { ltChart.legend.position = s.selectedValue; updateMenuHeader(s, 'Legend Position'); }, selectedValue: 'Right' }); updateMenuHeader(ltLegPos, 'Legend Position');

Result (live):


The FlexPie control allows you to select data points by clicking or touching a pie slice. Use the selectionMode property to specify whether you want to allow selection by data point or no selection at all (default).

Setting the selctionMode property to Point causes the FlexPie to update the selection property when the user clicks on a pie slice, and to apply the "wj-state-selected" class to the selected element. Setting the FlexPie's selectionMode property to Series or None will disable selections within the control.

The FlexPie offers three additional properties to customize the selection:

<div id="selChart"></div> <div class="form-horizontal"> <div class="form-group"> <label class="col-md-3 control-label">Selected Item Offset</label> <div class="col-md-9"> <input id="selItemOffset" type="text" /> </div> </div> <div class="form-group"> <div class="col-md-offset-3 col-md-9"> <select id="selItemPos"> <option value="None">None</option> <option value="Left">Left</option> <option value="Top">Top</option> <option selected value="Right">Right</option> <option value="Bottom">Bottom</option> </select> </div> </div> <div class="form-group"> <div class="col-md-offset-3 col-md-9"> <div class="checkbox"> <label> <input id="selAnimated" type="checkbox" checked="checked"> Animated </label> </div> </div> </div> </div>
var selChart = new wijmo.chart.FlexPie('#selChart', { binding: 'value', bindingName: 'name', itemsSource: getData(), isAnimated: true, selectionMode: 'Point', selectedItemPosition: 'Top' }); // change chart properties var inputNumber = new wijmo.input.InputNumber('#selItemOffset', { min: 0, max: 0.5, step: 0.1, format: 'n', valueChanged: function (s, e) { if (s.value >= s.min && s.value <= s.max) { selChart.selectedItemOffset = s.value; } } }); var selItemPos = new wijmo.input.Menu('#selItemPos', { itemClicked: function (s, e) { selChart.selectedItemPosition = s.selectedValue; updateMenuHeader(s, 'Selected Item Position'); }, selectedValue: 'Top' }); updateMenuHeader(selItemPos, 'Selected Item Position'); document.getElementById('selAnimated').addEventListener('click', function (e) { chart.isAnimated = e.target.checked; });

Result (live):


The appearance of the FlexPie control is largely defined in CSS. In addition to the default theme, we include several professionally designed themes that customize the appearance of all Wijmo controls to achieve a consistent, attractive look.

You can customize the appearance of the FlexPie control using CSS. To do this, copy the CSS rules from the default theme to a new CSS file and modify the rules as needed.

In this example, we added the "custom-pie-chart" CSS class to the control and defined some CSS rules to change the fill, font family, and font weight of the header, footer, and legend.

<div id="themeChart" class="custom-pie-chart"></div>
var themeChart = new wijmo.chart.FlexPie('#themeChart', { binding: 'value', bindingName: 'name', itemsSource: getData(), header: 'Header', footer: 'Footer' });
/* pie with custom styling */ .custom-pie-chart.wj-flexpie .wj-header .wj-title, .custom-pie-chart.wj-flexpie .wj-footer .wj-title, .custom-pie-chart.wj-flexpie .wj-legend > .wj-label { fill: #666; font-family: 'Courier New', Courier, monospace; font-weight: bold; }

Result (live):