PieChart Methods

This section describes the methods that can be used in code to manipulate the dxPieChart object.

Use the dxPieChart registered method to access the dxPieChart object, as demonstrated in the code below.

var pieChart = $("#pieChartContainer").dxPieChart("instance");

beginUpdate()

Prevents the widget from refreshing until the endUpdate method is called.

The beginUpdate and endUpdate methods allow you to apply several modifications to the widget at once. After the beginUpdate method is called, the widget does not rerender itself until the endUpdate method is called. The usage of these methods prevents excessive widget updating when changing multiple widget settings at once.

NOTE: It is recommended that you do not perform any actions on a widget within the updating transaction other than changing widget options.

clearSelection()

Deselects the chart's selected series. The series is displayed in an initial style.

To learn about series selection, refer to the Selection Handling help section.

Show Example:
jQuery

In this example, click a slice to select it. Since the pointSelectionMode is set to multiple, more than one slice can be selected. To deselect all the slices, click the 'Clear selected points' button. The chart's clearSelection() method will be called.

<div id="pieChartContainer" style="height:400px; max-width:600px; margin: 0 auto"></div>
<div style="height:25px;max-width:500px;margin:5px auto;font-family:'Trebuchet MS',Arial,sans-serif;font-size:14px;text-align:center">
    <input type="button" id="clearSelectedSeriesButton" value="Clear selected points" />
</div>
var dataSource = [
    { continent: 'Africa', population: 1022234000 },
    { continent: 'Antarctica', population: 4490 },
    { continent: 'Asia', population: 4164252000 },
    { continent: 'Australia', population: 29127000 },
    { continent: 'Europe', population: 738199000 },
    { continent: 'North America', population: 542056000 },
    { continent: 'South America', population: 392555000 }
];

$(function () {
    $("#pieChartContainer").dxPieChart({
        dataSource: dataSource,
        series: {
            argumentField: 'continent',
            valueField: 'population'
        },
        title: 'Population by Continent',
        pointSelectionMode: 'multiple',
        pointClick: function (clickedPoint) {
            clickedPoint.select()
        }
    });

    $('#clearSelectedSeriesButton').click(function () {
        var pieChart = $('#pieChartContainer').dxPieChart('instance');
        pieChart.clearSelection();
    });
});

endUpdate()

Enables the widget to refresh after the beginUpdate method call.

The beginUpdate and endUpdate methods allow you to apply several modifications to the widget at once. After the beginUpdate method is called, the widget does not rerender itself until the endUpdate method is called. The usage of these methods prevents excessive widget updating when changing multiple widget settings at once.

NOTE: It is recommended that you do not perform any actions on a widget within the updating transaction other than changing widget options.

getSeries()

Provides access to the dxPieChart's series.

Return Value: Object
The dxPieChart's series.

Show Example:
jQuery

In this example, you can show tooltips using the button below. When clicking the Show next tooltip button, the showTooltip() method of the next point in the order will be called. Access to this point is provided by the chart's getSeries() and the series' getAllPoints() methods.

<div id="pieChartContainer" style="height:400px; max-width:600px; margin: 0 auto"></div>
<div id="buttonContainer" style="height:40px;width:250px;margin:5px auto;font-family:'Trebuchet MS',Arial,sans-serif;font-size:14px">
    <input type='button' id='tooltipShow' value='Show next tooltip'>
</div>
var dataSource = [
    { continent: 'Africa', population: 1022234000 },
    { continent: 'Antarctica', population: 4490 },
    { continent: 'Asia', population: 4164252000 },
    { continent: 'Australia', population: 29127000 },
    { continent: 'Europe', population: 738199000 },
    { continent: 'North America', population: 542056000 },
    { continent: 'South America', population: 392555000 }
];

$(function () {
    $("#pieChartContainer").dxPieChart({
        dataSource: dataSource,
        series: {
            type: 'doughnut',
            argumentField: 'continent',
            valueField: 'population'
        },
        title: 'Population by Continent',
        tooltip: {
            format: 'largeNumber',
            precision: 2
        }
    });

    var clickCounter = 0;
    $('#tooltipShow').click(function () {
        var pieChart = $("#pieChartContainer").dxPieChart("instance");
        var series = pieChart.getSeries();
        var points = series.getAllPoints();
        if (clickCounter == dataSource.length)
            clickCounter = 0;
        points[clickCounter].showTooltip();
        clickCounter++;
    });
});

hideLoadingIndicator()

Conceals the loading indicator.

Although the loading indicator hides automatically when a chart is ready, you can hide it from code at the required time using the hideLoadingIndicator() method.

To show the loading indicator, invoke the showLoadingIndicator() method.

Show Example:
jQuery

In this example, the chart options are assigned five seconds after the example is loaded. You can show/hide the loading indicator using the buttons under the chart. Note that the loading indicator can be displayed or concealed manually at any time no matter whether the chart is ready or not.

<div id="pieChartContainer" style="height:400px; max-width:600px; margin: 0 auto"></div>
<div style="height:25px;max-width:500px;margin:5px auto;font-family:'Trebuchet MS',Arial,sans-serif;font-size:14px;text-align:center">
    <input type="button" id="showLoadingIndicatorButton" value="showLoadingIndicator()" />
    <input type="button" id="hideLoadingIndicatorButton" value="hideLoadingIndicator()" />
</div>
var dataSource = [
    { category: 'Oceania', value: 35 },
    { category: 'Africa', value: 1016 },
    { category: 'Americas', value: 936 },
    { category: 'Asia', value: 4149 },
    { category: 'Europe', value: 728 }
];

var chartOptions = {
    series: {
        argumentField: 'category',
        valueField: 'value',
        label: {
            visible: true,
            connector: { visible: true }
        }
    },
    title: 'Continental Population by 2010 (in millions)',
    legend: {
        horizontalAlignment: 'center',
        verticalAlignment: 'bottom'
    },
    dataSource: dataSource
};

$(function () {
    $("#pieChartContainer").dxPieChart().dxPieChart('instance').showLoadingIndicator();

    $('#showLoadingIndicatorButton').click(function () {
        var chart = $('#pieChartContainer').dxPieChart('instance');
        chart.showLoadingIndicator();
    });

    $('#hideLoadingIndicatorButton').click(function () {
        var chart = $('#pieChartContainer').dxPieChart('instance');
        chart.hideLoadingIndicator();
    });
});

var configureChart = function () {
    var chart = $("#pieChartContainer").dxPieChart('instance');
    chart.option(chartOptions);
};

setTimeout(configureChart, 5000);

hideTooltip()

Hides all widget tooltips.

Use this method to hide all widget tooltips programmatically.

Show Example:
jQuery

In this example, you can show and hide tooltips using the corresponding buttons below. When clicking the Show next tooltip button, the showTooltip() method of the next point in the order will be called. When clicking the Hide all tooltips button, the chart's hideTooltip() method will be called. This method clears the chart plot from tooltips.

<div id="pieChartContainer" style="height:400px; max-width:600px; margin: 0 auto"></div>
<div id="buttonsContainer" style="height:40px;width:250px;margin:5px auto;font-family:'Trebuchet MS',Arial,sans-serif;font-size:14px">
    <input type='button' id='tooltipShow' value='Show next tooltip'>
    <input type='button' id='tooltipHide' value='Hide all tooltips'>
</div>
var dataSource = [
    { continent: 'Africa', population: 1022234000 },
    { continent: 'Antarctica', population: 4490 },
    { continent: 'Asia', population: 4164252000 },
    { continent: 'Australia', population: 29127000 },
    { continent: 'Europe', population: 738199000 },
    { continent: 'North America', population: 542056000 },
    { continent: 'South America', population: 392555000 }
];

$(function () {
    $("#pieChartContainer").dxPieChart({
        dataSource: dataSource,
        series: {
            argumentField: 'continent',
            valueField: 'population'
        },
        title: 'Population by Continent',
        tooltip: {
            format: 'largeNumber',
            precision: 2
        }
    });

    var clickCounter = 0;
    $('#tooltipShow').click(function () {
        var pieChart = $("#pieChartContainer").dxPieChart("instance");
        var series = pieChart.getSeries();
        var points = series.getAllPoints();
        if (clickCounter == dataSource.length)
            clickCounter = 0;
        points[clickCounter].showTooltip();
        clickCounter++;
    });

    $('#tooltipHide').click(function () {
        var pieChart = $("#pieChartContainer").dxPieChart("instance");
        pieChart.hideTooltip();
    });
});

instance()

Returns an instance of the widget.

Return Value: Object
An instance of the widget.

Use this method to access the widget.

Show Example:
jQuery

In the following example, the instance() method is used to get access to the chart options. This method is called not like the other methods. To call the instance() method, the following construction is used:

<!--JavaScript -->$("#pieChartContainer").dxPieChart("instance")

Use the button below to show the tooltip of the next point in order.

<div id="pieChartContainer" style="height:400px; max-width:600px; margin: 0 auto"></div>
<div id="buttonContainer" style="height:40px;width:250px;margin:5px auto;font-family:'Trebuchet MS',Arial,sans-serif;font-size:14px">
    <input type='button' id='tooltipShow' value='Show next tooltip'>
</div>
var dataSource = [
    { continent: 'Africa', population: 1022234000 },
    { continent: 'Antarctica', population: 4490 },
    { continent: 'Asia', population: 4164252000 },
    { continent: 'Australia', population: 29127000 },
    { continent: 'Europe', population: 738199000 },
    { continent: 'North America', population: 542056000 },
    { continent: 'South America', population: 392555000 }
];

$(function () {
    $("#pieChartContainer").dxPieChart({
        dataSource: dataSource,
        series: {
            type: 'doughnut',
            argumentField: 'continent',
            valueField: 'population'
        },
        title: 'Population by Continent',
        tooltip: {
            format: 'largeNumber',
            precision: 2
        }
    });

    var clickCounter = 0;
    $('#tooltipShow').click(function () {
        var pieChart = $("#pieChartContainer").dxPieChart("instance");
        var series = pieChart.getSeries();
        var points = series.getAllPoints();
        if (clickCounter == dataSource.length)
            clickCounter = 0;
        points[clickCounter].showTooltip();
        clickCounter++;
    });
});

option()

Returns the object representing the configuration options of the widget.

Return Value: Object
The object representing the configuration options of the widget.

Use the fields of the returned object to configure the widget.

Show Example:
jQuery

In this example, the option() method is used to obtain the value of the legend | visible option and display it under the chart. To change this value, use the check box below.

<div id="pieChartContainer" style="height:400px; max-width:600px; margin: 0 auto"></div>
<div id="checkboxContainer" style="height:40px;width:300px;margin:5px auto;font-family:'Trebuchet MS',Arial,sans-serif;font-size:14px; text-align:center">
    <input type="checkbox" id="visibleLegendCheckbox" checked> Show Legend<br />
    <span id="selectionSpan" />
</div>
var dataSource = [
    { continent: 'Africa', population: 1022234000 },
    { continent: 'Antarctica', population: 4490 },
    { continent: 'Asia', population: 4164252000 },
    { continent: 'Australia', population: 29127000 },
    { continent: 'Europe', population: 738199000 },
    { continent: 'North America', population: 542056000 },
    { continent: 'South America', population: 392555000 }
];

$(function () {
    $("#pieChartContainer").dxPieChart({
        dataSource: dataSource,
        series: {
            argumentField: 'continent',
            valueField: 'population'
        },
        title: 'Population by Continent'
    });

    $('#visibleLegendCheckbox').change(function () {
        var pieChart = $("#pieChartContainer").dxPieChart("instance");
        pieChart.option({
            legend: { visible: this.checked }
        });
        var chartOptions = pieChart.option();
        $('#selectionSpan').html('legend | visible : ' + chartOptions.legend.visible);
    });
});

option(optionName)

Gets the value of the specified configuration option of the widget.

Parameters:
optionName: String
The name of the option to get.
Return Value: any
The value of the specified option.

To get the value of a configuration option, specify the path to the field representing this option in the configuration object. For example, pass the "tooltip.enabled" value as the optionName parameter to get the value of the tooltip | enabled option.

Show Example:
jQuery

In this example, the option(optionName) method is used to obtain the value of the tooltip | enabled option and display it under the chart. To change this value, use the check box below.

<div id="pieChartContainer" style="height:400px; max-width:600px; margin: 0 auto"></div>
<div id="checkboxContainer" style="height:40px;width:300px;margin:5px auto;font-family:'Trebuchet MS',Arial,sans-serif;font-size:14px; text-align:center">
    <input type="checkbox" id="enableTooltipCheckbox" checked> Enable Tooltips<br />
    <span id="selectionSpan" />
</div>
var dataSource = [
    { continent: 'Africa', population: 1022234000 },
    { continent: 'Antarctica', population: 4490 },
    { continent: 'Asia', population: 4164252000 },
    { continent: 'Australia', population: 29127000 },
    { continent: 'Europe', population: 738199000 },
    { continent: 'North America', population: 542056000 },
    { continent: 'South America', population: 392555000 }
];

$(function () {
    $("#pieChartContainer").dxPieChart({
        dataSource: dataSource,
        series: {
            argumentField: 'continent',
            valueField: 'population'
        },
        title: 'Population by Continent',
        animation: false,
        tooltip: {
            enabled: true,
            format: 'largeNumber',
            precision: 2
        }
    });

    $('#enableTooltipCheckbox').change(function () {
        var pieChart = $("#pieChartContainer").dxPieChart("instance");
        pieChart.option({
            tooltip: { enabled: this.checked }
        });
        $('#selectionSpan').html('tooltip | enabled : ' + pieChart.option('tooltip.enabled'));
    });
});

option(optionName, optionValue)

Sets a value to the specified configuration option of the widget.

Parameters:
optionName: String
The name of the required option.
optionValue: any
The value to be assigned to the required option.

To set a value to the configuration option, specify the path to the field representing this option in the configuration object. For example, to set the tooltip | enabled option to true, pass the "tooltip.enabled" value as the optionName parameter and the "true" value as the optionValue parameter.

Show Example:
jQuery

In this example, the option(optionName, optionValue) method is used to set the value of the tooltip | enabled option at runtime. To change this value, use the check box below.

<div id="pieChartContainer" style="height:400px; max-width:600px; margin: 0 auto"></div>
<div id="checkboxContainer" style="height:40px;width:300px;margin:5px auto;font-family:'Trebuchet MS',Arial,sans-serif;font-size:14px; text-align:center">
    <input type="checkbox" id="enableTooltipCheckbox" checked> Enable Tooltips
</div>
var dataSource = [
    { continent: 'Africa', population: 1022234000 },
    { continent: 'Antarctica', population: 4490 },
    { continent: 'Asia', population: 4164252000 },
    { continent: 'Australia', population: 29127000 },
    { continent: 'Europe', population: 738199000 },
    { continent: 'North America', population: 542056000 },
    { continent: 'South America', population: 392555000 }
];

$(function () {
    $("#pieChartContainer").dxPieChart({
        dataSource: dataSource,
        series: {
            argumentField: 'continent',
            valueField: 'population'
        },
        title: 'Population by Continent',
        animation: false,
        tooltip: {
            enabled: true,
            format: 'largeNumber',
            precision: 2
        }
    });

    $('#enableTooltipCheckbox').change(function () {
        var pieChart = $("#pieChartContainer").dxPieChart("instance");
        pieChart.option('tooltip.enabled', this.checked);
    });
});

option(options)

Sets one or more widget options.

Parameters:
options: Object
An object containing required configuration options.

To set one or more widget options, pass the object that contains fields representing these options as the options parameter.

This method is useful if you need to configure several widget options at once.

Show Example:
jQuery

In this example, the option(options) method is used to alter a set of options at once. To change the values of the tooltip | enabled and tooltip | arrowLength options, use the check box below.

<div id="pieChartContainer" style="height:400px; max-width:600px; margin: 0 auto"></div>
<div id="checkboxContainer" style="height:40px;width:300px;margin:5px auto;font-family:'Trebuchet MS',Arial,sans-serif;font-size:14px; text-align:center">
    <input type="checkbox" id="changeTooltipCheckbox" checked> Change Several Tooltip Options<br />
</div>
var dataSource = [
    { continent: 'Africa', population: 1022234000 },
    { continent: 'Antarctica', population: 4490 },
    { continent: 'Asia', population: 4164252000 },
    { continent: 'Australia', population: 29127000 },
    { continent: 'Europe', population: 738199000 },
    { continent: 'North America', population: 542056000 },
    { continent: 'South America', population: 392555000 }
];

$(function () {
    $("#pieChartContainer").dxPieChart({
        dataSource: dataSource,
        series: {
            argumentField: 'continent',
            valueField: 'population'
        },
        title: 'Population by Continent',
        animation: false,
        tooltip: {
            enabled: true,
            format: 'largeNumber',
            precision: 2,
            arrowLength: 5
        }
    });

    $('#changeTooltipCheckbox').change(function () {
        var pieChart = $("#pieChartContainer").dxPieChart("instance");
        var tooltipArrow = pieChart.option('tooltip.arrowLength');
        pieChart.option({
            tooltip: {
                enabled: this.checked,
                arrowLength: tooltipArrow + 10
            }
        });
    });
});

render(renderOptions)

Redraws a widget.

Parameters:
renderOptions: Object
An object containing rerendering options.

By default, a widget rerenders when the size of the parent window is changed. But there may be situations when a chart must be rerendered manually, i.e., when the size of the chart's container is changed. To rerender a widget, use the render method.

Call the render method without a parameter after the size of the chart's container is changed. Alternatively, call the render method with an options object as the parameter. This object should contain the force field set to 'true'. In addition, you can use this object to specify whether or not to perform animation on rerendering with the animate field, and whether or not to rerender the chart in an asynchronous mode with the asyncSeriesRendering field.

The following code sample illustrates the example of the object to be passed as the renderOptions parameter.

JavaScript
var renderOptions = {
    force: true,
    animate: false,
    asyncSeriesRendering: false
}
Show Example:
jQuery

Click the 'Change the container size' button to switch between two sizes of the chart container. You can set the size either to 400x600 or 300x500 pixels. The render method without parameters is used to redraw the chart after the container size changes.

<div id="pieChartContainer" style="height:400px; max-width:600px; margin: 0 auto"></div>
<div style="height:25px;max-width:500px;margin:0px auto;font-family:'Trebuchet MS',Arial,sans-serif;font-size:14px;text-align:center">
    <input type="button" id="changeContainerSizeButton" value="Change the container size" />
</div>
var dataSource = [
    { continent: 'Africa', population: 1022234000 },
    { continent: 'Antarctica', population: 4490 },
    { continent: 'Asia', population: 4164252000 },
    { continent: 'Australia', population: 29127000 },
    { continent: 'Europe', population: 738199000 },
    { continent: 'North America', population: 542056000 },
    { continent: 'South America', population: 392555000 }
];

$(function () {
    $("#pieChartContainer").dxPieChart({
        dataSource: dataSource,
        series: {
            argumentField: 'continent',
            valueField: 'population'
        },
        title: 'Population by Continent'
    });

    $('#changeContainerSizeButton').click(function () {
        var pieChart = $('#pieChartContainer').dxPieChart('instance');
        if ($('#pieChartContainer').height() > 300 || $('#pieChartContainer').width() > 500) {
            $('#pieChartContainer').height(300);
            $('#pieChartContainer').width(500);
        } else {
            $('#pieChartContainer').height(400);
            $('#pieChartContainer').width(600);
        }
        pieChart.render();
    });
});

showLoadingIndicator()

Displays the loading indicator.

The loading indicator does not appear automatically. In order to display it, the showLoadingIndicator() method should be invoked.

To hide the loading indicator from code, use the hideLoadingIndicator() method.

Show Example:
jQuery

In this example, the showLoadingIndicator() method invokes when the example loads. Note that it is not necessary to conceal the loading indicator using the hideLoadingIndicator() method, since it executes automatically.

<div id="pieChartContainer" style="height:400px; max-width:600px; margin: 0 auto"></div>
var dataSource = [
    { category: 'Oceania', value: 35 },
    { category: 'Africa', value: 1016 },
    { category: 'Americas', value: 936 },
    { category: 'Asia', value: 4149 },
    { category: 'Europe', value: 728 }
];

var chartOptions = {
    series: {
        argumentField: 'category',
        valueField: 'value',
        label: {
            visible: true,
            connector: { visible: true }
        }
    },
    title: 'Continental Population by 2010 (in millions)',
    legend: {
        horizontalAlignment: 'center',
        verticalAlignment: 'bottom'
    },
    dataSource: dataSource
};

$(function () {
    $("#pieChartContainer").dxPieChart().dxPieChart('instance').showLoadingIndicator();
});

var configureChart = function () {
    var chart = $("#pieChartContainer").dxPieChart('instance');
    chart.option(chartOptions);
};

setTimeout(configureChart, 3000);

svg()

Returns the widget's SVG markup.

Return Value: String
The widget's SVG markup.

NOTE: This method does not support Internet Explorer 8.

Show Example:
jQuery

Click the Get SVG below the chart, and the SVG copy of this chart will appear.

<div style="display:inline-block">
    <div id="pieChartContainer" style="height:400px; max-width:400px; margin: 0 auto; display: inline-block"></div>
    <div id="widgetSVG" style="height:400px;max-width:400px;margin: 5px auto;display:inline-block"></div>
</div>
<div style="height:30px; max-width:800px;font-family:'Trebuchet MS',Arial,sans-serif;font-size:14px;text-align:center;">
    <input type='button' id='getSVG' value='Get SVG'>
</div>
var dataSource = [
    { continent: 'Africa', population: 1022234000 },
    { continent: 'Antarctica', population: 4490 },
    { continent: 'Asia', population: 4164252000 },
    { continent: 'Australia', population: 29127000 },
    { continent: 'Europe', population: 738199000 },
    { continent: 'North America', population: 542056000 },
    { continent: 'South America', population: 392555000 }
];

$(function () {
    $("#pieChartContainer").dxPieChart({
        dataSource: dataSource,
        series: {
            type: 'doughnut',
            argumentField: 'continent',
            valueField: 'population'
        },
        tooltip: {
            format: 'largeNumber',
            precision: 2
        }
    });

    $("#getSVG").click(function () {
        var pieChart = $('#pieChartContainer').dxPieChart('instance');
        $('#widgetSVG').html(pieChart.svg());
    });
});