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#.
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);
<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
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
Thank you Ekaterina.
I was able to get the desired results only after following the second step.