PieChart

The PieChart is a widget that visualizes data as a circle divided into sectors that each represents a portion of the whole.

Included in: dx.viz.js, dx.viz-web.js, dx.all.js
Module: viz/pie_chart
Export: default
PieChart interactive configuration
Copy Code
Copy to Codepen
$("#piechart").dxPieChart({
});

                    

You can create the widget using one of the following approaches.

  • jQuery

    HTML
    JavaScript
    <div id="pieChart"></div>
    var fruits = [
        { fruit: 'Oranges', yield: 10, consumed: 7 },
        { fruit: 'Apples', yield: 15, consumed: 14 },
        { fruit: 'Bananas', yield: 9, consumed: 9 }
    ];
    $(function() {
        $("#pieChart").dxPieChart({
            dataSource: fruits,
            commonSeriesSettings: {
                argumentField: "fruit"
            },
            series: [
                { valueField: "yield" },
                { valueField: "consumed" }
            ]
        });
    });
  • Angular

    HTML
    JavaScript
    <dx-pie-chart [dataSource]="fruits">
        <dxo-common-series-settings argumentField="fruit"></dxo-common-series-settings>
        <dxi-series valueField="yeld"></dxi-series>
        <dxi-series valueField="consumed"></dxi-series>
    </dx-pie-chart>
    export class AppComponent {
        fruits = [
            // ...   
        ];
    }
  • AngularJS

    HTML
    JavaScript
    <div ng-controller="DemoController">
        <div dx-pie-chart="{
            dataSource: fruits,
            commonSeriesSettings: {
                argumentField: 'fruit'
            },
            series: [
                { valueField: 'yield' },
                { valueField: 'consumed' }
            ]
        }"></div>
    </div>
    angular.module('DemoApp', ['dx'])
        .controller("DemoController", function ($scope) {
            $scope.fruits = [
                // ...   
            ];
        });
  • Knockout

    HTML
    JavaScript
    <div data-bind="dxPieChart: {
        dataSource: fruits,
        commonSeriesSettings: {
            argumentField: 'fruit'
        },
        series: [
            { valueField: 'yield' },
            { valueField: 'consumed' }
        ]
    }"></div>
    var viewModel = {
        fruits: [
            // ...
        ]
    };
    ko.applyBindings(viewModel);
  • ASP.NET MVC Wrappers

    Razor C#
    Razor VB
    @(Html.DevExtreme().PieChart()
        .ID("pieChart")
        .DataSource(Fruits)
        .CommonSeriesSettings(c => c
            .ArgumentField("fruit")
        )
        .Series(series => {
            series.Add().ValueField("yield");
            series.Add().ValueField("consumed");
        })
    )
    @(Html.DevExtreme().PieChart() _
        .ID("pieChart") _
        .DataSource(Fruits) _
        .CommonSeriesSettings(Sub(c)
            c.ArgumentField("fruit")
        End Sub) _
        .Series(Sub(series)
            series.Add().ValueField("yield")
            series.Add().ValueField("consumed")
        End Sub)

Note that DevExtreme widgets require you to link the jQuery library to your application. If you use the Knockout or AngularJS approach, the Knockout or AngularJS library is also required. For detailed information on linking these libraries to your project, refer to the topics in the Installation section.

View Demo Watch Video

See Also

Configuration

An object that defines configuration options for the PieChart widget.

Name Description
adaptiveLayout

Specifies adaptive layout options.

animation

Specifies animation options.

commonSeriesSettings

An object defining the configuration options that are common for all series of the PieChart widget.

customizeLabel

Specifies a callback function that returns an object with options for a specific point label.

customizePoint

Specifies a callback function that returns an object with options for a specific point.

dataSource

Specifies the origin of data for the widget.

diameter

Specifies the diameter of the pie.

elementAttr

Specifies the attributes to be attached to the widget's root element.

export

Configures the exporting and printing features.

innerRadius

Specifies the fraction of the inner radius relative to the total radius in the series of the 'doughnut' type. The value should be between 0 and 1.

legend

Specifies PieChart legend options.

loadingIndicator

Configures the loading indicator.

margin

Generates space around the widget.

minDiameter

Specifies the minimum diameter of the pie.

onDisposing

A handler for the disposing event.

onDone

A handler for the done event.

onDrawn

A handler for the drawn event.

onExported

A handler for the exported event.

onExporting

A handler for the exporting event.

onFileSaving

A handler for the fileSaving event.

onIncidentOccurred

A handler for the incidentOccurred event.

onInitialized

A handler for the initialized event. Executed only once, after the widget is initialized.

onLegendClick

A handler for the legendClick event.

onOptionChanged

A handler for the optionChanged event.

onPointClick

A handler for the pointClick event.

onPointHoverChanged

A handler for the pointHoverChanged event.

onPointSelectionChanged

A handler for the pointSelectionChanged event.

onTooltipHidden

A handler for the tooltipHidden event.

onTooltipShown

A handler for the tooltipShown event.

palette

Sets the name of the palette to be used in the chart. Alternatively, an array of colors can be set as a custom palette to be used within this chart.

pathModified

Notifies the widget that it is embedded into an HTML page that uses a tag modifying the path.

pointSelectionMode

Specifies whether a single point or multiple points can be selected in the chart.

redrawOnResize

Specifies whether to redraw the widget when the size of the parent browser window changes or a mobile device rotates.

resolveLabelOverlapping

Specifies how a chart must behave when series point labels overlap.

rtlEnabled

Specifies whether or not the widget supports right-to-left representation.

segmentsDirection

Specifies the direction that the pie chart segments will occupy.

series

Specifies options for the series of the PieChart widget.

seriesTemplate

Defines options for the series template.

size

Specifies the size of the widget in pixels.

startAngle

Specifies the angle in arc degrees from which the first segment of a pie chart should start.

theme

Sets the name of the theme to be used in the widget.

title

Specifies the widget title.

tooltip

Configures tooltips.

type

Specifies the type of the pie chart series.

Methods

This section describes the methods that can be used in code to manipulate the PieChart widget.

Name Description
beginUpdate()

Prevents the component from refreshing until the endUpdate() method is called.

clearSelection()

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

element()

Returns the root HTML element of the widget.

endUpdate()

Enables the component to refresh after the beginUpdate() method call.

exportTo(fileName, format)

Exports the widget into a document with a specified name and format.

getAllSeries()

Returns an array of all series in the chart.

getDataSource()

Returns the DataSource instance.

getSeriesByName(seriesName)

Gets a series within the chart's series collection by the specified name (see the name option).

getSeriesByPos(seriesIndex)

Gets a series within the chart's series collection by its position number.

getSize()

Gets the current size of the widget.

hideLoadingIndicator()

Conceals the loading indicator.

hideTooltip()

Hides all widget tooltips.

instance()

Returns an instance of this component class.

off(eventName)

Detaches all event handlers from the specified event.

off(eventName, eventHandler)

Detaches a particular event handler from the specified event.

on(eventName, eventHandler)

Subscribes to a specified event.

on(events)

Subscribes to the specified events.

option()

Returns the configuration options of this component.

option(optionName)

Gets the value of the specified configuration option of this component.

option(optionName, optionValue)

Sets a value to the specified configuration option of this component.

option(options)

Sets one or more options of this component.

print()

Opens the browser's print window.

render()

Redraws the widget.

render(renderOptions)

Redraws a widget.

showLoadingIndicator()

Displays the loading indicator.

svg()

Returns the widget's SVG markup.

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

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

Events

This section describes events fired by this widget.

Name Description
disposing

Fires when the widget is being removed.

done

Fires when the Series and Point chart elements are ready to be accessed.

drawn

Fires when the widget has finished drawing itself.

exported

Fires after data from the widget is exported.

exporting

Fires before data from the widget is exported.

fileSaving

Fires before a file with exported data is saved on the user's local storage.

incidentOccurred

Fires when an error or warning appears in a widget.

initialized

Raised only once, after the widget is initialized.

legendClick

Fires when an item on the chart legend is clicked.

optionChanged

Fires after an option of the component is changed.

pointClick

Fires when a user clicks a series point.

pointHoverChanged

Fires when the hover state of a series point has been changed.

pointSelectionChanged

Fires when the selection state of a series point has been changed.

tooltipHidden

Fires when a point's tooltip becomes hidden.

tooltipShown

Fires when a point's tooltip appears.

Series Types

This section lists the objects that define options to be used to configure series of particular types.

Chart Elements

This section lists the methods and fields of the PieChart elements.