Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
100
Binding Observable Collection to LineChart
posted

I looked through the forum and I found like one example of binding an Observable Collection to a Chart, but I was wondering if anyone had a good sample code or help me to do it. Right now Ihave the following Code:

<igCA:XamChart Name="xamChart1">
    <igCA:XamChart.Series>
        <igCA:Series ChartType="Line"
                        DataMapping="Label=ProductName;Value=Quantity;">
            <igCA:Series.DataSource>
                <local:LineData />
            </igCA:Series.DataSource>
        </igCA:Series>
    </igCA:XamChart.Series>
</igCA:XamChart>

 

    public class LineData : ObservableCollection<LineResults>
    {
        public LineData() : base()
        {

            this.Add(new LineResults() { ProductName = "Product A", Quantity = 1});
            this.Add(new LineResults() { ProductName = "Product B", Quantity = 2 });
            this.Add(new LineResults() { ProductName = "Product C", Quantity = 3 });
            this.Add(new LineResults() { ProductName = "Product D", Quantity = 4 });
        }
    }


    public class LineResults
    {
        public string ProductName { get; set; }
        public int Quantity { get; set; }
    }

 

But I would really like to have my Observable Collection in my LineGraph : Window class like the following:

 

public partial class LineChartPage : Window
{
        private ObservableCollection<LineResults> PatientResults;

        private LineResults temp1
        private LineResults temp2;


        public LineChartPage()
        {
            InitializeComponent();

            temp1= new LineResults
            {
                ProductName= "Temp",
                Quantity = 10
            };

            temp2= new LineResults
            {
                ProductName= "Temp",
                Quantity = 50
            };
            ///.......ECT
}

 

Is there a way to do this?

  • 100
    Verified Answer
    posted

    I got it....

    <igCA:XamChart Height="400" Width="800">

    <igCA:XamChart.Series>

    <igCA:Series ChartType="Line" DataSource="{Binding}" DataMapping="Label = ChosenAnswer; Value = Time;">

    <igCA:Series.Animation>

    <igCA:Animation BeginTime="00:00:00" Duration="00:00:05" AccelerationRatio=".2" DecelerationRatio="0.8" Sequential="True"/>

    </igCA:Series.Animation>

    </igCA:Series>

    </igCA:XamChart.Series>

    </igCA:XamChart>

     

     

        public class LineResults
        {
            public string ChosenAnswer { get; set; }
            public double Time { get; set; }
        }

     

    public LineGraphPage()
    {
                InitializeComponent();

                //Creat Observable Collection called Results

                DataContext = Results;
    }