Question

I've got the following XAML:

                    <amq:SerialChart Grid.Column="0" Grid.Row="0" DataSource="{Binding Data}" CategoryValueMemberPath="Date"
                         AxisForeground="White"
                         PlotAreaBackground="Black"
                         GridStroke="DarkGray">
                        <amq:SerialChart.Graphs>
                            <amq:LineGraph ValueMemberPath="Downfall" Title="Downfall" Brush="Blue" />
                        </amq:SerialChart.Graphs>
                    </amq:SerialChart>

And my code looks like this:

namespace DownfallControl
{
    public partial class MainPage : PhoneApplicationPage
    {
        private ObservableCollection<DownfallLog> Data = new ObservableCollection<DownfallLog>()
        {
            new DownfallLog() { Date = new DateTime(2012, 2, 2), Downfall = 90.1 },
            new DownfallLog() { Date = new DateTime(2012, 2, 3), Downfall = 89.6 },
            new DownfallLog() { Date = new DateTime(2012, 2, 4), Downfall = 85.6 }
        };

        public MainPage()
        {
            InitializeComponent();
        }

        private void MainPage_Loaded(object sender, RoutedEventArgs e)
        {
            this.DataContext = this;

            Data.Add(new DownfallLog() { Date = new DateTime(2012, 2, 6), Downfall = 85.6 });
        }        
    }

    public class DownfallLog
    {
        public double Downfall;
        public DateTime Date;
    }
}

Any clue why nothing is showing up?

Was it helpful?

Solution

The ObservableCollection has to be public and a property, so this:

   private ObservableCollection<DownfallLog> Data = new ObservableCollection<DownfallLog>()
    {
        new DownfallLog() { Date = new DateTime(2012, 2, 2), Downfall = 90.1 },
        new DownfallLog() { Date = new DateTime(2012, 2, 3), Downfall = 89.6 },
        new DownfallLog() { Date = new DateTime(2012, 2, 4), Downfall = 85.6 }
    };

should be this:

   public ObservableCollection<DownfallLog> Data {get;set;}

You can initialize the collection in your constructor.

These have to be properties as well:

   public class DownfallLog
   {
      public double Downfall {get;set;}
      public DateTime Date   {get;set;}
   }
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top