Hi
I am trying to convert some legacy code from your Silverlight xamWebChart to the WPF xmDataChart and am having problems due mainly to the lack of real world examples.
All our charts are rendered in code (no XAML) and I have succeeded in getting the Line Charts and the Column Charts working based on your DataTable example.
I cannot however get the Stacked Column Chart or the Pie Chart working based on a DataTable data source - can you provide any examples of these being created in code please?
Many thanks
Andrew Hunot
Hi Andrew
Oh so easy!
Many thanks again for your excellent support.
Regards
Andrew
Hello Andrew,
Currently, it appears that you are using a Legend element for usage with the XamPieChart's Legend property. While the chart will not complain about this assignment, it is not the legend type that the XamPieChart expects. I would recommend that you use an ItemLegend element for usage with the XamPieChart.Legend property instead.
A documentation article showing that the XamPieChart expects an ItemLegend can be found here: http://help.infragistics.com/doc/WPF/2016.1/CLR4.0/?page=PieChart_Data_Binding.html.
Please let me know if you have any other questions or concerns on this matter.
Sincerely,AndrewAssociate Developer
Many thanks for the speedy response. I have now been able to create both stacked column and pie charts in code from a data table of variable length.
I have one remaining issue in that I cannot seem to get the legend for the pie chart working. My code is as follows:
Private Sub MakePieChart()
Dim errs As String = "" Dim dts As DataTable = sqld.GetDataTable(strSQL(chartType), errs) If dts.Rows.Count = 0 Then Exit Sub Dim srs(dts.Rows.Count - 1) As String
Dim dt As New DataTable() dt.Columns.Add(New DataColumn("Label", GetType(String))) dt.Columns.Add(New DataColumn("Value", GetType(Integer))) For r As Integer = 0 To dts.Rows.Count - 1 Dim row As DataRow = dt.NewRow() row("Label") = dts.Rows(r).Item(0).ToString row("Value") = dts.Rows(r).Item(1) dt.Rows.Add(row) Next
Dim DataChart As New XamPieChart() AddHandler DataChart.MouseDown, AddressOf ShowHideLegend DataChart.Margin = New Thickness(5) DataChart.DataContext = dt
DataChart.ItemsSource = dt.DefaultView DataChart.LabelMemberPath = "Label" DataChart.ValueMemberPath = "Value"
Dim legend As New Legend() With { .Content = "My Pie Chart", .Margin = New Thickness(20), .VerticalAlignment = VerticalAlignment.Top, .HorizontalAlignment = HorizontalAlignment.Right }
DataChart.Legend = legend
Me.LayoutRoot.Children.Add(DataChart)
Me.LayoutRoot.Children.Add(legend)
End Sub
Any ideas?
Thanks again
To begin, I would recommend that you take a look at the two following articles in our online documentation that show how to create a StackedColumnSeries programmatically in WPF:http://help.infragistics.com/doc/WPF/2016.1/CLR4.0/?page=DataChart_Category_Stacked_Column_Series.html.
It doesn't appear at the moment that our online documentation has a programmatic example for the XamPieChart, but the concept to take away from it is that you currently need to set the ItemsSource, LabelMemberPath, and ValueMemberPath properties of the XamPieChart for it to work. This can be seen here: http://help.infragistics.com/doc/WPF/2016.1/CLR4.0/?page=PieChart_Data_Binding.html.
The above documentation articles do not show usage with a DataTable, but the main idea is that the ItemsSource of the XamPieChart and the ItemsSource of the CategoryXAxis and StackedColumnSeries both expect a derivation of IEnumerable. The DataTable itself does not derive from this interface, but the DataView exposed by the DataTable's DefaultView property does, and so if you set the ItemsSource to your table's DefaultView in this case, everything should work normally.
To demonstrate this, I have created a sample project where I create both a XamPieChart and a XamDataChart with a StackedColumnSeries purely in C# code. This sample project is attached.
I hope this helps. Please let me know if you have any other questions or concerns on this matter.