JavaScript/jQuery PieChart API

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

import PieChart from "devextreme/viz/pie_chart"
Type:

Object

DevExtreme widgets are integrated with many popular libraries and frameworks. See the Installation section (for JavaScript libraries) or the Prerequisites and Installation section (for ASP.NET MVC framework) to find details on setting up DevExtreme with a particular library or framework.

The following code shows how to create the PieChart widget using every supported library and framework. For more details on working with widgets in these libraries and frameworks, see the Widget Basics topic for jQuery, Angular, AngularJS, Knockout or ASP.NET MVC.

jQuery
JavaScript
HTML
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" }
        ]
    });
});
<div id="pieChart"></div>
Angular
HTML
TypeScript
<dx-pie-chart [dataSource]="fruits">
    <dxo-common-series-settings argumentField="fruit"></dxo-common-series-settings>
    <dxi-series valueField="yield"></dxi-series>
    <dxi-series valueField="consumed"></dxi-series>
</dx-pie-chart>
import { DxPieChartModule } from "devextreme-angular";
// ...
export class AppComponent {
    fruits = [
        { fruit: "Oranges", yield: 10, consumed: 7 },
        { fruit: "Apples", yield: 15, consumed: 14 },
        { fruit: "Bananas", yield: 9, consumed: 9 }
    ];
}
@NgModule({
    imports: [
        // ...
        DxPieChartModule
    ],
    // ...
})
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 = [
            { fruit: "Oranges", yield: 10, consumed: 7 },
            { fruit: "Apples", yield: 15, consumed: 14 },
            { fruit: "Bananas", yield: 9, consumed: 9 }   
        ];
    });
Knockout
HTML
JavaScript
<div data-bind="dxPieChart: {
    dataSource: fruits,
    commonSeriesSettings: {
        argumentField: 'fruit'
    },
    series: [
        { valueField: 'yield' },
        { valueField: 'consumed' }
    ]
}"></div>
var viewModel = {
    fruits: [
        { fruit: "Oranges", yield: 10, consumed: 7 },
        { fruit: "Apples", yield: 15, consumed: 14 },
        { fruit: "Bananas", yield: 9, consumed: 9 }
    ]
};
ko.applyBindings(viewModel);
ASP.NET MVC Controls
Razor C#
Razor VB
@(Html.DevExtreme().PieChart()
    .ID("pieChart")
    .DataSource(new[] {
        new { Fruit = "Oranges", Yield = 10, Consumed = 7 },
        new { Fruit = "Apples", Yield = 15, Consumed = 14 },
        new { Fruit = "Bananas", Yield = 9, Consumed = 9 }
    })
    .CommonSeriesSettings(c => c
        .ArgumentField("Fruit")
    )
    .Series(series => {
        series.Add().ValueField("Yield");
        series.Add().ValueField("Consumed");
    })
)
@(Html.DevExtreme().PieChart() _
    .ID("pieChart") _
    .DataSource({
        New With { .Fruit = "Oranges", .Yield = 10, .Consumed = 7 },
        New With { .Fruit = "Apples", .Yield = 15, .Consumed = 14 },
        New With { .Fruit = "Bananas", .Yield = 9, .Consumed = 9 }
    }) _
    .CommonSeriesSettings(Sub(c)
        c.ArgumentField("Fruit")
    End Sub) _
    .Series(Sub(series)
        series.Add().ValueField("Yield")
        series.Add().ValueField("Consumed")
    End Sub)

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

Customizes the appearance of an individual point label.

customizePoint

Customizes the appearance of an individual series point.

dataSource

Specifies the widget's data origin.

diameter

Specifies the diameter of the pie.

disabled

Specifies whether the widget responds to the user interaction.

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 function that is executed before the widget is disposed of.

onDone

A function that is executed when all series are ready.

onDrawn

A function that is executed when the widget's rendering has finished.

onExported

A function that is executed after the widget is exported.

onExporting

A function that is executed before the widget is exported.

onFileSaving

A function that is executed before a file with exported widget is saved to the user's local storage.

onIncidentOccurred

A function that is executed when an error or warning occurs.

onInitialized

A function that is executed only once, after the widget is initialized.

onLegendClick

A function that is executed when a legend item is clicked or tapped.

onOptionChanged

A function that is executed after a widget option is changed.

onPointClick

A function that is executed when a series point is clicked or tapped.

onPointHoverChanged

A function that is executed after the pointer enters or leaves a series point.

onPointSelectionChanged

A function that is executed when a series point is selected or the selection is canceled.

onTooltipHidden

A function that is executed when a tooltip becomes hidden.

onTooltipShown

A function that is executed when a tooltip appears.

palette

Sets the palette to be used to colorize series and their elements.

paletteExtensionMode

Specifies what to do with colors in the palette when their number is less than the number of series (in the Chart widget) or points in a series (in the PieChart widget).

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 point labels overlap.

rtlEnabled

Switches the widget to a 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 widget's size in pixels.

sizeGroup

Allows you to display several adjoining pies in the same size.

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 the widget uses.

title

Configures the widget's 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 widget from refreshing until the endUpdate() method is called.

clearSelection()

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

dispose()

Disposes of all the resources allocated to the PieChart instance.

element()

Gets the root widget element.

endUpdate()

Refreshes the widget after a call of the beginUpdate() method.

exportTo(fileName, format)

Exports the widget.

getAllSeries()

Gets all the series.

getDataSource()

Gets the DataSource instance.

getInstance(element)

Gets the instance of a widget found using its DOM node.

getSeriesByName(seriesName)

Gets a series with a specific name.

getSeriesByPos(seriesIndex)

Gets a series with a specific index.

getSize()

Gets the current widget size.

hideLoadingIndicator()

Hides the loading indicator.

hideTooltip()

Hides all widget tooltips.

instance()

Gets the widget's instance. Use it to access other methods of the widget.

off(eventName)

Detaches all event handlers from a single event.

off(eventName, eventHandler)

Detaches a particular event handler from a single event.

on(eventName, eventHandler)

Subscribes to an event.

on(events)

Subscribes to events.

option()

Gets all widget options.

option(optionName)

Gets the value of a single option.

option(optionName, optionValue)

Updates the value of a single option.

option(options)

Updates the values of several options.

print()

Opens the browser's print window.

refresh()

Reloads data and repaints the widget.

render()

Redraws the widget.

render(renderOptions)

Redraws the widget.

showLoadingIndicator()

Shows the loading indicator.

svg()

Gets 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

Raised before the widget is disposed of.

done

Raised when all series are ready.

drawn

Raised when the widget's rendering has finished.

exported

Raised after the widget is exported.

exporting

Raised before the widget is exported.

fileSaving

Raised before a file with exported widget is saved to the user's local storage.

incidentOccurred

Raised when an error or warning occurs.

initialized

Raised only once, after the widget is initialized.

legendClick

Raised when a legend item is clicked or tapped.

optionChanged

Raised after a widget option is changed.

pointClick

Raised when a series point is clicked or tapped.

pointHoverChanged

Raised after the pointer enters or leaves a series point.

pointSelectionChanged

Raised when a series point is selected or the selection is canceled.

tooltipHidden

Raised when a tooltip becomes hidden.

tooltipShown

Raised when a tooltip appears.

See Also

Series Types

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

Name Description
DoughnutSeries

An object defining a series of the doughnut type.

PieSeries

An object defining a series of the pie type.

Type:

Object

Chart Elements

This section describes chart elements.