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.
Hey,
i'm having some difficulties with multiple series in one chart, each series placed alongside the other series.
i followed the Getting Started Tutorials but with no success, PLEASE try to see where i got wrong.
TNX
Sharon.
Result Snap:
My Code: (No XAML, ONLY C#)
public ValidationResults(SortedList<int, SortedList<int, double>> AvgList) {
InitializeComponent();
SimpleDataCollection data = new SimpleDataCollection(AvgList); XamDataChart DataChart = new XamDataChart(); DataChart.Margin = new Thickness(5); DataChart.DataContext = data;
ScaleLegend legend1 = new ScaleLegend { Content = "Legend", Margin = new Thickness(20), VerticalAlignment = VerticalAlignment.Top, HorizontalAlignment = HorizontalAlignment.Right };
// XAxis CategoryXAxis xmXAxis = new CategoryXAxis(); xmXAxis.ItemsSource = data; xmXAxis.Label = "{Label}";
xmXAxis.LabelSettings = new AxisLabelSettings(); //ADDED this line xmXAxis.LabelSettings.Extent = 35; xmXAxis.LabelSettings.Location = AxisLabelsLocation.OutsideBottom;
// YAxis NumericYAxis xmYAxis = new NumericYAxis(); xmYAxis.LabelSettings = new AxisLabelSettings();//ADDED this line xmYAxis.LabelSettings.Extent = 55; xmYAxis.LabelSettings.Location = AxisLabelsLocation.OutsideLeft; xmYAxis.MaximumValue = 100;
DataChart.Axes.Add(xmXAxis); DataChart.Axes.Add(xmYAxis); DataChart.FontStyle = FontStyles.Oblique;
// Ec2 Series LineSeries seriesEc2 = new LineSeries(); seriesEc2.Title = "E[C(2)]"; seriesEc2.Brush = new SolidColorBrush(Colors.Yellow); seriesEc2.ValueMemberPath = "ValueEc2"; seriesEc2.XAxis = xmXAxis; seriesEc2.YAxis = xmYAxis; seriesEc2.ItemsSource = data;
// Ec3 Series LineSeries seriesEc3 = new LineSeries(); seriesEc3.Title = "E[C(3)]"; seriesEc3.Brush = new SolidColorBrush(Colors.Red); seriesEc3.ValueMemberPath = "ValueEc3"; seriesEc3.XAxis = xmXAxis; seriesEc3.YAxis = xmYAxis; seriesEc3.ItemsSource = data;
// Ec4 Series LineSeries seriesEc4 = new LineSeries(); seriesEc4.Title = "E[C(4)]"; seriesEc4.Brush = new SolidColorBrush(Colors.Blue); seriesEc4.ValueMemberPath = "ValueEc4"; seriesEc4.XAxis = xmXAxis; seriesEc4.YAxis = xmYAxis; seriesEc4.ItemsSource = data;
DataChart.Series.Add(seriesEc2); DataChart.Series.Add(seriesEc3); DataChart.Series.Add(seriesEc4); this.chartPanel.Children.Add(DataChart); }
//*************************************
public class SimpleDataCollection : ObservableCollection<SimpleDataPoint> { public SimpleDataCollection(SortedList<int, SortedList<int, double>> AvgList) { foreach (KeyValuePair<int, double> pair in AvgList[2]) this.Add(new SimpleDataPoint() { Label = pair.Key.ToString(), ValueEc2 = pair.Value }); foreach (KeyValuePair<int, double> pair in AvgList[3]) this.Add(new SimpleDataPoint() {Label = pair.Key.ToString(), ValueEc3 = pair.Value }); foreach (KeyValuePair<int, double> pair in AvgList[4]) this.Add(new SimpleDataPoint() { Label = pair.Key.ToString(), ValueEc4 = pair.Value }); } } /// <summary> /// Simple storage class for pair of string and double value /// </summary> public class SimpleDataPoint { public double ValueEc2 { get; set; } public double ValueEc3 { get; set; } public double ValueEc4 { get; set; } public string Label { get; set; } }