i have problem with binding property of subclass to RadCartesianChart

7 posts, 0 answers
  1. Masoud
    Masoud avatar
    15 posts
    Member since:
    Aug 2013

    Posted 18 Nov 2014 Link to this post

    hi
    i wanna binding property of subclass in main class to radcartesianchart with barseries 
    i very tired  do this but dont work
    my code
    Model:
    class People
     {
         private string fristname;
         private string lastname;
         private Int32 salary;
         //private ObservableCollection<Company> _company=new ObservableCollection<Company>();
         private Company _company = new Company();
     
         public string FristName { get { return this.fristname; } set { this.fristname = value; } }
     
         public string LastName { get { return this.lastname; } set { this.lastname = value; } }
     
         public Int32 Salary { get { return this.salary; } set { this.salary = value; } }
     
         public Company Company
         {
             get { return this._company; }
             set { this._company = value; }
         }
     }
     
    public class Company
     {
         private string name;
         private Int32 cost;
     
         public string Name { get { return this.name; } set { this.name = value; } }
     
         public Int32 Cost
         {
             get { return this.cost; }
             set { this.cost = value; }
         }
     }

    ViewModel:
    class peopleViewModel : DependencyObject
       {
           public static readonly DependencyProperty DataProperty = DependencyProperty.Register("Data",
       typeof(ObservableCollection<People>),
       typeof(peopleViewModel),
       new PropertyMetadata(null));
     
     
           public ObservableCollection<People> Data
           {
               get
               {
                   return (ObservableCollection<People>)this.GetValue(DataProperty);
               }
               set
               {
                   this.SetValue(DataProperty, value);
               }
           }
     
     
     
     
           public peopleViewModel()
           {
               var data = new ObservableCollection<People>();
               data.Add(new People() { Company = new Company() { Cost = 1000, Name = "co1" } , FristName = "masoud1", LastName = "fallah1", Salary = 150 });
               data.Add(new People() { Company = new Company() { Cost = 2000, Name = "co2" } , FristName = "masoud2", LastName = "fallah2", Salary = 250 });
               data.Add(new People() { Company = new Company() { Cost = 3000, Name = "co3" } , FristName = "masoud3", LastName = "fallah3", Salary = 350 });
               data.Add(new People() { Company = new Company() { Cost = 4000, Name = "co4" } , FristName = "masoud4", LastName = "fallah4", Salary = 450 });
     
               Data = data;
           }
       }
    view:code-behind
    public partial class PeopleView : Page
      {
           
           
           
          public PeopleView()
          {
              InitializeComponent();
            peopleViewModel Data = new peopleViewModel();
     
            this.DataContext = Data;
           // pro.Source = Data;
               
               
          }
     
     
      }
    and view:
    <telerik:ChartDataSource x:Name="ChartDataSource1"
                        ItemsSource="{Binding Data}" Grid.RowSpan="2"
                    />
    <telerik:RadCartesianChart x:Name="RadChart1" Margin="0,0,0,10">
        <telerik:RadCartesianChart.HorizontalAxis>
            <telerik:DateTimeCategoricalAxis />
        </telerik:RadCartesianChart.HorizontalAxis>
        <telerik:RadCartesianChart.VerticalAxis>
            <telerik:LinearAxis/>
        </telerik:RadCartesianChart.VerticalAxis>
        <telerik:BarSeries x:Name="bar" ShowLabels="True"
                    CategoryBinding="{Binding Path=Company.Cost}"
                    ValueBinding="Salary"
                           ItemsSource="{Binding ElementName=ChartDataSource1}"
                           >
        </telerik:BarSeries>
    </telerik:RadCartesianChart>
    please help me :(
  2. Martin
    Admin
    Martin avatar
    1099 posts

    Posted 21 Nov 2014 Link to this post

    Hi Masoud,

    Note that when you set the CategoryBinding and ValueBinding properties in xaml they expect String value and then internally parse it to a DataPointBinding. In order to bind the Company.Cost property to the Category of the series you can pass the property's path as a string.

    <telerik:BarSeries x:Name="bar" ShowLabels="True"
                    CategoryBinding="Company.Cost"
                    ValueBinding="Salary"
                           ItemsSource="{Binding ElementName=ChartDataSource1}"
                           >
                </telerik:BarSeries>

    Or set it in code behind as demonstrated in the Create Data-Bound Chart help article.

    I hope this helps.

    Regards,
    Martin
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
  3. UI for WPF is Visual Studio 2017 Ready
  4. Masoud
    Masoud avatar
    15 posts
    Member since:
    Aug 2013

    Posted 23 Nov 2014 in reply to Martin Link to this post

    tx dear martin

    i have one ask

    how i can use this in rad chart ??
    i tried to use of  itemmapping but not work and this use datapointmember enum that have xcategory and etc

  5. Masoud
    Masoud avatar
    15 posts
    Member since:
    Aug 2013

    Posted 24 Nov 2014 Link to this post

    i can create radchart but for more 100 count i get error
    my code
      SeriesMapping mapping = new SeriesMapping();
      ItemMapping map1 = new ItemMapping("Buy_Legal_Sub.Volume", DataPointMember.YValue,Telerik.Windows.Controls.Charting.ChartAggregateFunction.Average);
      //map1.FieldType = typeof(DateTime);
      mapping.ItemMappings.Add(map1);
      ItemMapping map2 = new ItemMapping("Tarikh", DataPointMember.XCategory, Telerik.Windows.Controls.Charting.ChartAggregateFunction.Average);
        map2.FieldType = typeof(Int32);
        mapping.ItemMappings.Add(map2);
      radchart.ItemsSource =flow.Data;
      radchart.SeriesMappings.Add(mapping);
      radchart.DefaultView.ChartArea.AxisX.DefaultLabelFormat = "dd-MM-yy";
    }

    and my error is
    No generic method 'Average' on type 'System.Linq.Enumerable' is compatible with the supplied type arguments and arguments. No type arguments should be provided if the method is

    when i use less 100 record h dont have error and work chart but if number of record more 100 i get this error
  6. Martin
    Admin
    Martin avatar
    1099 posts

    Posted 26 Nov 2014 Link to this post

    Hello Masoud,

    Without your data and models I cannot be sure what is causing this error in your scenario. However, I was able to reproduce it locally in the following cases:
    • The property string path in the ItemMapping is mistyped and it does not match the property's name
    • The property is of type DateTime. The aggregate functions work with numeric values.
    I also attached a sample project that demonstrates RadChart with the settings from the code snippet which you provided in your last reply. Can you please take a look at it and let me know if I am missing something?

    Furthermore, keep in mind that RadChart is our old charting components which has many known issues and limitations. This is why we created the new RadChartView suite that resolves many of the issues of RadChart. The new components have better implementation and improved performance, also, they are very flexible and easier to set up. You can read about the differences between the charts in the RadChart vs. RadChartView help article. In general, we recommend our clients to use RadChartView.

    Regards,
    Martin
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
  7. Masoud
    Masoud avatar
    15 posts
    Member since:
    Aug 2013

    Posted 16 Apr 2015 in reply to Martin Link to this post

    hi dear admin

    i upload sample project that similar is demo wpf

    please check this project and find problem because i tried to solve this problem but i cant

    http://speedy.sh/tYk93/test.rar

  8. Martin
    Admin
    Martin avatar
    1099 posts

    Posted 20 Apr 2015 Link to this post

    Hi Masoud,

    As I can see the provided example is not runnable and I guess this is the mentioned issues. The following reasons causes the build to fail:
    • The Telerik dll's are missing from the referenced assemblies of the project
    • The DataSourceViewModelBase should be abstract because it defines abstract methods
    • There was several uses of a "testchart" namespace - actually the namespace should be test
    • There are several wrong URI paths - they should use the following pattern in order to work properly: "/test;component/folderName/fileName.extension"
    • The "telerikQuickStart" namespace used in XAML is not contained in any of our assemblies, but it is the namespace of a project created in the solution that holds the UI for WPF examples. The QuickStart class is used for the headers and configuration panels in the demos. 

    For your convenience I updated the project and attached it in my reply. However, keep in mind if you have a license for UI for WPF you can find the runnable solution with our demos under your account's download page.

    Regards,
    Martin
    Telerik
     

    See What's Next in App Development. Register for TelerikNEXT.

     
Back to Top
UI for WPF is Visual Studio 2017 Ready