I am trying to create a XamChart with the following code, but cannt seem to get it to work.
System.Data.DataTable dt;
dt.Columns.Add("Series Label", typeof(string));
dt.Columns.Add("Segment B", typeof(int));
dt.Columns.Add("SegmentD", typeof(int));
dt.Rows.Add(new object[ { "Stack B", 2, 140, 4, 2 });
dt.Rows.Add(new object[ { "Stack D", 3, 5, 5, 7 });
{
c = new Infragistics.Windows.Chart.Series();
c.DataSource = dt.Rows[i];
xamChart1.Series.Add(c);
}
Please give me some pointers to where I am going wrong. Thank you.
Hi,
DataMapping is the means for assigning data to the various parts of a XamChart. Performing dynamic queries is possible. I do not have a working example how to perform a dynamic query. If you need help implementing one, you could contact developer support as they can work directly with you in helping you solve any issue with any of our products.
http://ko.infragistics.com/support/default.aspx
Thank you,
In WinChart you don't need to specify the DataMapping, just need
dataSource = dataTable.DefaultView. winChart will combine Seg A, Seg B, Seg C and Seg D automatically. So I don't need to know the column names in advanced, this feature is very useful for a dynamic query. But in WPF you have to specify column names, How stupid it is! How can I create a chart based on a dynamic query?
Check out the documentation for the XamChart. It comes with various samples. The fastest data source would probably be an ObservableCollection of data with a DataMapping assigned.
If you need more samples, I would be happy to post one here.
Are there any recommended ways of binding data to the XamChart? If you have any code snippets for various chart types and methods of binding it to the xamchart, that will be very helpful.
Hello Curtis
Thank you for the code. My mistake was in assigning the row to the DataSource rather than the entire datatable in each series. I didnt know how to do the datamapping either.
Thanks again. I am attaching my final code in case anyone is interested.
System.Data.DataTable dt;dt = new System.Data.DataTable();dt.Columns.Add("Series Label", typeof(string));dt.Columns.Add("Segment A", typeof(int));dt.Columns.Add("Segment B", typeof(int));dt.Columns.Add("Segment C", typeof(int));dt.Columns.Add("Segment D", typeof(int));dt.Rows.Add(new object[ { "Stack A", 1, 4, 5, 200 });dt.Rows.Add(new object[ { "Stack B", 2, 140, 4, 2 });dt.Rows.Add(new object[ { "Stack C", 5, 10, 9, 15 });dt.Rows.Add(new object[ { "Stack D", 3, 5, 5, 7 });Series c = new Infragistics.Windows.Chart.Series();xamChart1.Series.Clear();c.ChartType = ChartType.Stacked100Bar;for (int i = 1; i < 5; i++){c = new Infragistics.Windows.Chart.Series();c.ChartType = ChartType.Stacked100Bar;c.DataSource = dt;c.DataMapping = "Value=" + dt.Columns[i].ColumnName + ";Label=" + dt.Columns[0].ColumnName;xamChart1.Series.Add(c);}