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
40
Problem in setting Xamdatachart through C#
posted

I tried replicating the graph given at the link https://help.infragistics.com/Help/Doc/WindowsPhone/2011.1/CLR4.0/html/xamDataChart_Getting_Started_with_xamDataChart.html 

I was able to get the desired output when created the graph in Xaml, but not in C#.

My C# code is given below.

 

 

 SimpleDataCollection data = new SimpleDataCollection();

            XamDataChart datachart = new XamDataChart();

            datachart.Margin = new Thickness(5);

            datachart.DataContext = data;

 

 

            //------------------Initialize the axes

            //------X Axis

            CategoryXAxis xmAxis = new CategoryXAxis();

            xmAxis.Label = "{Label}";

            xmAxis.ItemsSource = data;

            AxisLabelSettings abs = new AxisLabelSettings();

            abs.Extent = 35;

            abs.Location = AxisLabelsLocation.OutsideTop;

            xmAxis.LabelSettings = abs;

 

            //------Y Axis

            NumericYAxis ymAxis = new NumericYAxis();

            AxisLabelSettings yaxissetting = new AxisLabelSettings();

            ymAxis.DataContext = data;

            yaxissetting.Extent = 55;

            yaxissetting.Location = AxisLabelsLocation.OutsideRight;

            ymAxis.LabelSettings = yaxissetting;

 

 

            datachart.Axes.Add(xmAxis);

            datachart.Axes.Add(ymAxis);

 

            //-------------------------------Adding Spline

            SplineAreaSeries series = new SplineAreaSeries();

            series.ValueMemberPath = "Value";

            series.DataContext = data;

            series.XAxis = xmAxis;

            series.YAxis = ymAxis;

            datachart.Series.Add(series);

            this.LayoutRoot.Children.Add(datachart);    

 

And my corresponding xaml code is (its working fine)

 

 <Grid x:Name="LayoutRoot">

        <ig:XamDataChart x:Name="DataChart">

            <ig:XamDataChart.DataContext>

                <Models:SimpleDataCollection/>

            </ig:XamDataChart.DataContext>

            <ig:XamDataChart.Axes>

                <ig:CategoryXAxis x:Name="xmAxis" ItemsSource="{Binding}" Label="{}{Label}">

                    <ig:CategoryXAxis.LabelSettings>

                        <ig:AxisLabelSettings Location="OutsideTop" Extent="35"/>

                    </ig:CategoryXAxis.LabelSettings>

                </ig:CategoryXAxis>

                <ig:NumericYAxis x:Name="ymAxis">

                    <ig:NumericYAxis.LabelSettings>

                        <ig:AxisLabelSettings Location="InsideTop" Extent="55"/>

                    </ig:NumericYAxis.LabelSettings>

                </ig:NumericYAxis>

            </ig:XamDataChart.Axes>

            <ig:XamDataChart.Series>

                <ig:SplineAreaSeries ValueMemberPath="Value" ItemsSource="{Binding}" XAxis="{Binding ElementName=xmAxis}" YAxis="{Binding ElementName=ymAxis}"></ig:SplineAreaSeries>

            </ig:XamDataChart.Series>

        </ig:XamDataChart>

 

    </Grid>

 

 

 

Kindly help me where I am getting it wrong.      

 

 

Regards

Rajat Saini

Parents
  • 4475
    Verified Answer
    posted

    Hello,

     

    I have been looking into your question and I tested your code within my own application. During my investigation I found where the issue was, so in order to have your sample working, please perform the following:

     

    1)      In your NumericYAxis declaration please remove the assignment of the dataContext:

     

    ymAxis.DataContext = data; (remove this)

     

    2)      In the SplineAreaSerie declaration please replace the dataContext declaration with ItemsSource declaration:

     

    series.DataContext = data;  -> replace with ->  series.ItemsSource = data;

     

    When I did the above mentioned changes, my xamDataChart behaved as expected and the series were successfully added.

     

    Please let me know if you have future concerns regarding the discussed matter.

     

    Sincerely,

    Ekaterina

    Developer Support Engineer

    Infragistics, Inc.

    www.infragistics.com/support

     

Reply Children