Ticket T197360
Visible to All Users

WPF Pie Chart - Legend and Labels MVVM DataBinding

created 10 years ago

I am trying to produce a simple pie chart with numeric values and labels for each value.  I am using an MVVM pattern and am trying to avoid code in the code behind.  I have a simple object being bound as the series data source:

C#
public class ViewModel { public ObservableCollection<DataPoint> DataPoints } public class DataPoint { public string Name { get; set; } public decimal Value { get; set; } public override string ToString() { return Name; } }

When I produce the chart, the legend and datapoints on the chart itself do not show the data point Name.  I am using a binding expression like the below:

XAML
<dxc:PieSeries2D ArgumentDataMember="Name" ValueDataMember="Value" LabelsVisibility="True" HoleRadiusPercent="0" DataSource="{Binding Path=PointsCollection, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type Window}}}"> </dxc:PieSeries2D>

I have attached a sample project.  How would I use a DataTemplate for both the Legend and the series point labels to be able to render the values on the model that I am using as the series datasource?

Also, how to I specify that I don't want percentages, I want the actual numbers?

Answers approved by DevExpress Support

created 10 years ago

To achieve this goal set the Series.LegendPointOptions.PointView and  Series.PointOptions.PointView properties to  "ArgumentAndValues".

C#
<dxc:PieSeries2D.LegendPointOptions> <dxc:PointOptions PointView="ArgumentAndValues" > ... </dxc:PointOptions> </dxc:PieSeries2D.LegendPointOptions> <dxc:PieSeries2D.PointOptions> <dxc:PointOptions PointView="ArgumentAndValues"/> </dxc:PieSeries2D.PointOptions>

Attached is your modified sample project that illustrates this approach.

    Show previous comments (1)
    DevExpress Support Team 10 years ago

      You are welcome Jason,
      I am happy to hear that you have found my assistance helpful.
      Also I suggest you review the following topics:
      PointOptions.PointView Property
      PointView Enumeration

        Hi,
        I am looking at real time update of pie chart with above example using MVVM. One way i found was chartControl.Update method. But, if I update  Value property of DataPoint  and  DataPoint is implemented INotifiyPropertyChanged, chart is not updating.
        Can you please suggest, is there any way to update real time using MVVM?

        DevExpress Support Team 9 years ago

          Hi Naveen,
          To avoid discussing multiple problems in a single thread, I have created a separate ticket on your behalf: How to update a pie chart at real time using MVVM. Let's continue our discussion there.

          Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

          Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.