webdad3
webdad3

Reputation: 9080

wp7 ObservableCollection population

I'm using the AMCharts control and I'm trying to follow the example however, I'm not sure how I get the data out of my historyItemCollection (fig 1) into an Observable collection (fig 2)?

Fig 1:

from item in App.ViewModel.historyItemCollection
where item.VehicleId == (Application.Current as App).vehicleId
select item;

Fig 2:

private ObservableCollection<TestDataItem> _data = new ObservableCollection<TestDataItem>()
{
    new TestDataItem() { axis = "Mar", value=5},
    new TestDataItem() { axis = "Apr", value=15.2},
    new TestDataItem() { axis = "May", value=25},
    new TestDataItem() { axis = "June", value=8.1},
};

In the historyitemcollection I have a date item that I would put in the axis value as well as a cost item that I would put in the value value (fig 2:)

How can I get my data into the observableCollection so I can use this chart control?

Upvotes: 0

Views: 219

Answers (1)

Claus J&#248;rgensen
Claus J&#248;rgensen

Reputation: 26344

_data = new ObservableCollection<HistoryItem>
(
    from item in App.ViewModel.historyItemCollection
    where item.VehicleId == (Application.Current as App).vehicleId
    select item;
)

or if at runtime

var historyItems =
    from item in App.ViewModel.historyItemCollection
    where item.VehicleId == (Application.Current as App).vehicleId
    select item;

foreach (var item in historyItems)
    _data.Add(item);

Upvotes: 1

Related Questions