Back to Devexpress

SimpleDiagram2D Class

wpf-devexpress-dot-xpf-dot-charts-dot-simplediagram2d.md

latest11.6 KB
Original Source

SimpleDiagram2D Class

Represents a diagram that is used to plot non-XY 2D series.

Namespace : DevExpress.Xpf.Charts

Assembly : DevExpress.Xpf.Charts.v25.2.dll

NuGet Package : DevExpress.Wpf.Charts

Declaration

csharp
public class SimpleDiagram2D :
    Diagram2D,
    ISimpleDiagram,
    IDiagram,
    IHitTestableElement
vb
Public Class SimpleDiagram2D
    Inherits Diagram2D
    Implements ISimpleDiagram,
               IDiagram,
               IHitTestableElement

Remarks

After you set the ChartControl.Diagram property to the SimpleDiagram2D type, only a series of the PieSeries2D types can be added to the Diagram.Series collection.

For more information, refer to Diagram and Series Type Compatibility.

Example

This example demonstrates how to create a 2D Pie chart.

Create a ChartControl and specify its ChartControl.Diagram property to a SimpleDiagram2D object.

View Example

Note

Note that the ChartControl.Diagram is a content property. You can declare a diagram in XAML directly after a chart control’s declaration without wrapping it in opening and closing ChartControl.Diagram tags.

Add a PieSeries2D object to the Diagram.Series collection.

Note

Note that the Diagram.Series is a content property. You can declare series in XAML directly after a diagram’s declaration without wrapping them in opening and closing Diagram.Series tags.

Use the following properties to bind the series to data:

The PieSeries2D.Model property allows you to change the series appearance using the built-in models. This example uses the GlarePie2DModel model.

Use the Series.LegendTextPattern property to specify how to format text that identifies series points in the legend.

Set the Series.LabelsVisibility property to true to display the series’s labels. The SeriesLabel.TextPattern property defines how to configure series labels’ text.

The PieTotalLabel.TextPattern property allows you to specify the center label’s content.

View Example

xaml
<Window x:Class="PieDonut2DChart.Window1" 
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
        xmlns:dxc="http://schemas.devexpress.com/winfx/2008/xaml/charts"
        xmlns:local="clr-namespace:PieDonut2DChart"
        Title="Window1" Height="470" Width="700">
    <Window.DataContext>
        <local:ChartViewModel/>
    </Window.DataContext>
    <Grid>
        <dxc:ChartControl Name="chartControl">
            <dxc:SimpleDiagram2D>
                <dxc:PieSeries2D x:Name="series" 
                                 DisplayName="Sales" 
                                 DataSource="{Binding Path=Data}"
                                 ArgumentDataMember="Argument" 
                                 ValueDataMember="Value"
                                 LabelsVisibility="True" 
                                 LegendTextPattern="{}{A}: {V}"
                                 HoleRadiusPercent="50">
                    <!--region #Model-->
                    <dxc:PieSeries2D.Model>
                        <dxc:GlarePie2DModel/>
                    </dxc:PieSeries2D.Model>
                    <!--endregion #Model-->
                    <dxc:PieSeries2D.TotalLabel>
                        <dxc:PieTotalLabel TextPattern="Total:&#x0a;{TV}"/>
                    </dxc:PieSeries2D.TotalLabel>
                    <dxc:PieSeries2D.Label>
                        <dxc:SeriesLabel TextPattern="{}{VP:P}" 
                                         dxc:PieSeries.LabelPosition="TwoColumns"/>
                    </dxc:PieSeries2D.Label>
                </dxc:PieSeries2D>
            </dxc:SimpleDiagram2D>
            <dxc:ChartControl.Legends>
                <dxc:Legend>
                    <dxc:Legend.Title>
                        <dxc:LegendTitle Content="Units Sold"/>
                    </dxc:Legend.Title>
                </dxc:Legend>
            </dxc:ChartControl.Legends>
        </dxc:ChartControl>
    </Grid>
</Window>
csharp
using System.Collections.ObjectModel;
using System.Windows;

namespace PieDonut2DChart {
    public partial class Window1 : Window {
        public Window1() {
            InitializeComponent();
        }
    }
    public class ChartViewModel {
        public Collection<DataPoint> Data { get; private set; }
        public ChartViewModel() {
            Data = new Collection<DataPoint> {
                        new DataPoint ("Bikes", 142345),
                        new DataPoint ("Accessories", 266344),
                        new DataPoint ("Components", 631359),
                        new DataPoint ("Clothing", 120007)
            };
        }
        public class DataPoint {
            public string Argument { get; private set; }
            public double Value { get; private set; }
            public DataPoint(string argument, double value) {
                Argument = argument;
                Value = value;
            }
        }
    }
}
vb
Imports System.Collections.ObjectModel
Imports System.Windows

Namespace PieDonut2DChart
    Partial Public Class Window1
        Inherits Window

        Public Sub New()
            InitializeComponent()
        End Sub
    End Class
    Public Class ChartViewModel
        Private privateData As Collection(Of DataPoint)
        Public Property Data() As Collection(Of DataPoint)
            Get
                Return privateData
            End Get
            Private Set(ByVal value As Collection(Of DataPoint))
                privateData = value
            End Set
        End Property
        Public Sub New()
            Data = New Collection(Of DataPoint) From { _
                New DataPoint("Bikes", 142345), _
                New DataPoint("Accessories", 266344), _
                New DataPoint("Components", 631359), _
                New DataPoint("Clothing", 120007) _
            }
        End Sub
        Public Class DataPoint
            Private privateArgument As String
            Public Property Argument() As String
                Get
                    Return privateArgument
                End Get
                Private Set(ByVal value As String)
                    privateArgument = value
                End Set
            End Property
            Private privateValue As Double
            Public Property Value() As Double
                Get
                    Return privateValue
                End Get
                Private Set(ByVal value As Double)
                    privateValue = value
                End Set
            End Property
            Public Sub New(ByVal argument As String, ByVal value As Double)
                Me.Argument = argument
                Me.Value = value
            End Sub
        End Class
    End Class
End Namespace

The following code snippets (auto-collected from DevExpress Examples) contain references to the SimpleDiagram2D class.

Note

The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.

wpf-charts-add-custom-legend-item-to-legend/CS/CustomLegendItemSample/MainWindow.xaml#L33

xml
<!--endregion #CustomItems-->
<dxc:SimpleDiagram2D>
    <dxc:PieSeries2D LegendTextPattern="{}{A}: {VP:P0}">

wpf-data-grid-display-chart-control-in-grid-details/CS/WpfApplication19/MainWindow.xaml#L21

xml
<dxc:ChartControl DataSource="{Binding Path=Orders}" Grid.Column="1" Height="200" Margin="10,10,10,10">
    <dxc:SimpleDiagram2D>
        <dxc:SimpleDiagram2D.Series>

wpf-data-grid-create-master-detail-grid-in-code/CS/MasterDetailInCode/MainWindow.xaml#L18

xml
<dxc:ChartControl DataSource="{Binding Path=Orders}">
    <dxc:SimpleDiagram2D>
        <dxc:SimpleDiagram2D.Series>

Inheritance

Show 12 items

Object DispatcherObject DependencyObject Visual UIElement FrameworkElement Control ChartElementBase ChartElement Diagram Diagram2D SimpleDiagram2D

See Also

SimpleDiagram2D Members

Diagram

Series Type Compatibility

DevExpress.Xpf.Charts Namespace