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

Binding to a DataSeriesCollection

1 Answer 83 Views
Chart
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Jurie
Top achievements
Rank 1
Jurie asked on 02 Feb 2011, 04:44 PM
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}" >

1 Answer, 1 is accepted

Sort by
0
Evgenia
Telerik team
answered on 08 Feb 2011, 08:34 AM
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>>
Tags
Chart
Asked by
Jurie
Top achievements
Rank 1
Answers by
Evgenia
Telerik team
Share this question
or