Binding Datapoint dynamically using property ?

2 posts, 0 answers
  1. Saravanan
    Saravanan avatar
    36 posts
    Member since:
    Jun 2011

    Posted 27 Jul 2011 Link to this post

    Hi,i have a rad chart pie series,i want to show two series, i have to bind the YPoint value dyanamically because i am using MVVM pattern,so i wrote this code,
     <telerik:ChartArea LegendName="ChartLegendManufacturers">
     
                    <telerik:ChartArea.DataSeries>
     
                        <telerik:DataSeries>
     
                            <telerik:DataSeries.Definition>
                                <telerik:PieSeriesDefinition ItemLabelFormat="#Y"></telerik:PieSeriesDefinition>
     
                            </telerik:DataSeries.Definition>
     
                            <telerik:DataPoint YValue="{Binding Items.OilPercetnage }" />
     
                            <telerik:DataPoint YValue="{Binding Items.WaterPercentage }" />
     
                        </telerik:DataSeries>
     
                    </telerik:ChartArea.DataSeries>
     
                </telerik:ChartArea>
     
     
    and here is the code behind,
     public PieChart()
            {
                this.LayoutRoot.DataContext = this;
                InitializeComponent();
                BindCharData();          
     
            }
            public ObservableCollection<TradeData> BindCharData()
            {
     
                Items = TradeData.GetWeeklyData();
                return Items;
            }
     public class OilData
        {
             
            public double OilPercetnage {get;set;}
            
            public double WaterPercentage {get;set;}
             
            public static ObservableCollection<OilData> GetWeeklyData()
            {
                ObservableCollection<OilData> tradeData = new ObservableCollection<OilData>();
                tradeData.Add(new OilData { OilPercetnage = 98, WaterPercentage = 55 });
                
                return tradeData;
            }
     
     
        }
     
    its shows error like "Object Null Value Reference ..please let me know,
     
    Thank you,
    Saravanan
  2. Sia
    Admin
    Sia avatar
    745 posts

    Posted 29 Jul 2011 Link to this post

    Hello Saravanan,

    I have modified your code in order to make it work correctly. Please review the attachment.

    Regards,
    Sia
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get now >>

Back to Top