This is a migrated thread and some comments may be shown as answers.

i have problem with binding property of subclass to RadCartesianChart

8 Answers 470 Views
Chart
This is a migrated thread and some comments may be shown as answers.
Masoud
Top achievements
Rank 1
Masoud asked on 18 Nov 2014, 02:00 PM
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 :(

8 Answers, 1 is accepted

Sort by
0
Martin Ivanov
Telerik team
answered on 21 Nov 2014, 08:59 AM
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.

 
0
Masoud
Top achievements
Rank 1
answered on 23 Nov 2014, 02:33 PM
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

0
Masoud
Top achievements
Rank 1
answered on 24 Nov 2014, 09:17 AM
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
0
Martin Ivanov
Telerik team
answered on 26 Nov 2014, 09:57 AM
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.

 
0
Masoud
Top achievements
Rank 1
answered on 16 Apr 2015, 11:05 AM

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

0
Martin Ivanov
Telerik team
answered on 20 Apr 2015, 07:59 AM
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.

 
0
rohith
Top achievements
Rank 1
answered on 14 Nov 2017, 12:17 PM

I have the following class structure;

public class ChartDataRecord
    {
        public ChartDataRecord(DeviceRecord valueY, int valueX)
        {
              ValueY = valueY;
              ValueX = valueX;
        }

        public DeviceRecord ValueY { get; private set; }
        public int ValueX { get; set; }

}

public class DeviceRecord
{
        public TriMagnitude Accelerations { get; set; } = new TriMagnitude(SystemUnits.Acceleration, 0, 0, 0);

}

 

public struct TriMagnitude
{
private float _xRaw;
private float _yRaw;
private float _zRaw;
private SystemUnits _systemUnit;

public SystemUnits SystemUnit { get { return _systemUnit; } }
public float X { get { return Units.ConvertToDisplayUnit(_xRaw, _systemUnit); } }
public float Y { get { return Units.ConvertToDisplayUnit(_yRaw, _systemUnit); } }
public float Z { get { return Units.ConvertToDisplayUnit(_zRaw, _systemUnit); } }

}

 

I am using an observableCollection to hold the data points;

public ObservableCollection<ChartDataRecord> ControlChartSeries;

 

This is how I am trying to bind;

<telerik:RadCartesianChart Name="AccelerationPlot" Grid.Row="2" Grid.Column="1" DataContext="{Binding Path=ControlChartSeries}">
            <telerik:RadCartesianChart.Behaviors>
                <telerik:ChartPanAndZoomBehavior DragMode="Pan" PanMode="Horizontal" ZoomMode="Horizontal"/>
                <telerik:ChartTrackBallBehavior ShowTrackInfo="True" />
            </telerik:RadCartesianChart.Behaviors>
            <telerik:RadCartesianChart.HorizontalAxis>
                <telerik:CategoricalAxis MajorTickInterval="5"/>
            </telerik:RadCartesianChart.HorizontalAxis>
            <telerik:RadCartesianChart.VerticalAxis>
                <telerik:LinearAxis />
            </telerik:RadCartesianChart.VerticalAxis>
            <telerik:RadCartesianChart.Series>

                <telerik:LineSeries Tag="X" CategoryBinding="ValueX"  ValueBinding="ValueY.Accelerations.X" ItemsSource="{Binding}" Stroke="#F37121">
                    <telerik:LineSeries.LegendSettings>
                        <telerik:SeriesLegendSettings Title="X" />
                    </telerik:LineSeries.LegendSettings>
                </telerik:LineSeries>

</telerik:RadCartesianChart.Series>
        </telerik:RadCartesianChart>

 

 

This is giving the following exception when running,

Couldn't find property 'ValueY.Accelerations.X' for type 'Mocks.Example_Viewmodels_ChartDataRecord_35_35412365'

 

 

Any help will be appericiable.

0
Martin Ivanov
Telerik team
answered on 14 Nov 2017, 12:32 PM
Hello Rohith,

The binding properties of the series (ValueBinding, CategoryBinding, etc.), doesn't work with chained properties (ex: ValueY.Accelerations.X). You can give only a direct property of the data point view model. To achieve your requirement you can define the ValueBinding in code and set its ValueSelector to a function that gets the ValueY.Accelerations.X property value. You can see this shown in the Create Data-Bound Chart article.

Regards,
Martin Ivanov
Progress Telerik
Want to extend the target reach of your WPF applications, leveraging iOS, Android, and UWP? Try UI for Xamarin, a suite of polished and feature-rich components for the Xamarin framework, which allow you to write beautiful native mobile apps using a single shared C# codebase.
Tags
Chart
Asked by
Masoud
Top achievements
Rank 1
Answers by
Martin Ivanov
Telerik team
Masoud
Top achievements
Rank 1
rohith
Top achievements
Rank 1
Share this question
or