Binding to a DataSeriesCollection

2 posts, 0 answers
  1. Jurie
    Jurie avatar
    6 posts
    Member since:
    Feb 2009

    Posted 02 Feb 2011 Link to this post

    Hi, is it possible to bind to a DataSeriesCollection, something along these lines:

    ViewModel:
    private DataSeriesCollection _chartDataSeries;
    public DataSeriesCollection ChartDataSeries
    {
        get { return _chartDataSeries ?? (_chartDataSeries = new DataSeriesCollection()); }
        set
        {
            if (_chartDataSeries == value) return;
      
            _chartDataSeries = value;
            NotifyPropertyChanged(() => ChartDataSeries);
        }
    }
      
    public void AddDataSeries(DataSeries series)
    {
        ChartDataSeries.Add(series);
    }

    with the dataseries being created like this:
    public Type TargetSeriesDefinition { get; set; }
      
    public DataSeries GetDataSeries(IEnumerable<StudyData> points, string label)
    {
        SeriesDefinition seriesDefinition = null;
      
        if (TargetSeriesDefinition != null)
        {
            if (TargetSeriesDefinition.FullName != null)
            {
                seriesDefinition = TargetSeriesDefinition.Assembly.CreateInstance(TargetSeriesDefinition.FullName) as SeriesDefinition;
            }
        }
      
        if (seriesDefinition == null) return null;
      
        seriesDefinition.ItemStyle = Application.Current.Resources["DragAndDropItemsStyle"] as Style;
        seriesDefinition.Appearance.Cursor = Cursors.Hand;
      
      
        var series = new DataSeries()
                         {
                             Definition = seriesDefinition,
                             LegendLabel = label
                         };
      
        points.ToList().ForEach(point => series.Add(new DataPoint{ XValue = point.Date.ToOADate(), YValue = point.Value}));
      
        return series;
    }

    The scenario I am  trying to support is manually creating the series based on a stringvalue being dropped onto the chart, as well as being able to drag serioes between different charts, combined with the ability to dynaimcally select the type of series to be displayed on each chart. I cant do it in codebehind because the charts are instantiated via a datatemplate as part of an itemscontrol.

    I tried:
    <Charting:ChartArea ItemsSource="{Binding ChartDataSeries}" >

    and
    <Charting:ChartArea Series="{Binding ChartDataSeries}" >

    but both throws exceptions.
    <Charting:ChartArea ItemsSource="{Binding ChartDataSeries}" >

    <Charting:ChartArea ItemsSource="{Binding ChartDataSeries}" >

  2. Evgenia
    Admin
    Evgenia avatar
    1437 posts

    Posted 08 Feb 2011 Link to this post

    Hi Jurie,

    Could you send us a sample project representing the issue you are facing so that we will be able to investigate it and help you?

    Looking forward to hearing from you!

    Best wishes,
    Evgenia
    the Telerik team
    Let us know about your Windows Phone 7 application built with RadControls and we will help you promote it. Learn more>>
Back to Top