I'm sorry if my question too silly. I try to bind DataTable with xamDataChart. Here is my code. As a result I see rectangle and one line. Could you tell me where my mistake is?
MainDataSet.Tables.Add("ChartTable");
MainDataSet.Tables["ChartTable"].Columns.Add("XCoordinate");
MainDataSet.Tables["ChartTable"].Columns.Add("YCoordinate");
for (int i = 0; i < 5; i++)
{
DataRow NewRow1 = MainDataSet.Tables["ChartTable"].NewRow();
MainDataSet.Tables["ChartTable"].Rows.Add(NewRow1);
MainDataSet.Tables["ChartTable"].Rows[i]["XCoordinate"] = i;
MainDataSet.Tables["ChartTable"].Rows[i]["YCoordinate"] = 2*i;
}
xamChartMainPosition.DataContext = MainDataSet.Tables["ChartTable"];
<
<ig:XamDataChart.Axes>
</ig:XamDataChart.Series>
</ig:XamDataChart>
Graham,
it helps! It's working! Thank you very much!!
Here is an example of how you can convert a data table to a collection of a nominal type and bind it to the chart.The Xaml:
<igChart:XamDataChart x:Name="theChart"> <igChart:XamDataChart.Axes> <igChart:NumericYAxis x:Name="yAxis" /> <igChart:CategoryXAxis x:Name="xAxis" ItemsSource="{Binding}" Label="{}{Label}"/> </igChart:XamDataChart.Axes> <igChart:XamDataChart.Series> <igChart:ColumnSeries x:Name="series" ItemsSource="{Binding}" XAxis="{Binding ElementName=xAxis}" YAxis="{Binding ElementName=yAxis}" ValueMemberPath="Value" /> </igChart:XamDataChart.Series> </igChart:XamDataChart>
And the code behind:
public partial class MainWindow : Window { public MainWindow() { InitializeComponent(); var data = from row in GetTestData() .Rows.OfType<DataRow>() select new DataItem() { Label = (string)row["Label"], Value = (double)row["Value"] }; DataContext = data; } public DataTable GetTestData() { DataTable testData = new DataTable(); testData.Columns.Add(new DataColumn("Label", typeof(string))); testData.Columns.Add(new DataColumn("Value", typeof(double))); DataRow dr = testData.NewRow(); dr["Label"] = "A"; dr["Value"] = 1; testData.Rows.Add(dr); dr = testData.NewRow(); dr["Label"] = "B"; dr["Value"] = 2; testData.Rows.Add(dr); dr = testData.NewRow(); dr["Label"] = "C"; dr["Value"] = 3; testData.Rows.Add(dr); dr = testData.NewRow(); dr["Label"] = "D"; dr["Value"] = 4; testData.Rows.Add(dr); return testData; } } public class DataItem { public string Label { get; set; } public double Value { get; set; } }
Hope this helps!-Graham
thanks for the reply.
It would be very nice to bind through DataTable.
I tried to use nominal class as you suggested, but all my attempts were unsuccessful. Could you give me a little working example that draws a broken line by 3-5 points?
Hi,
The XamDataChart doesn't currently support string indexers for its MemberPaths. You are welcome to make a feature request for this functionality, and hopefully we can accomodate soon. In the meantime you should create a nominal class to bind against rather than the rows:
public class DataItem { public double XValue { get; set; } public double YValue { get; set; } }
Hope this helps!