Binding DataSet to Charts

Charts for WPF Forum

Posted 10 years ago by Soraya
Version: 14.1.0602
Avatar

Dear Support team,

I want to show data from a dataset in actipro charts, I have tried diffrent methods,one is here, but I could not find any solution. it does not show any error and niether it shows any results.

Thanks,

Soraya

 

 

<charts:XYChart x:Name="XyChart">
<charts:AreaSeries x:Name="AreaSeries" XPath="{Binding Path=Name}" YPath="{Binding Path=No1}" YAxis="{Binding Source={x:Reference DgGrid}}"/>
</charts:XYChart>

 

public partial class MainWindow : Window
{
private List<string> Namen = new List<string>{ "sam", "mark", "Norah", "Max" };
private List<int> Values = new List<int> { 1, 2, 3, 4 };

public MainWindow()
{
InitializeComponent();
Table1();
}
private void Table1()
{
DataTable table1 = new DataTable("Customers");
table1.Columns.Add("Name");
table1.Columns.Add("No1");
table1.Columns.Add("No2");
table1.Rows.Add("sam", 1, 3.3);
table1.Rows.Add("mark", 2, 1.2);
table1.Rows.Add("Norah", 3, 2.2);
table1.Rows.Add("Max", 4, 1.2);
DataSet set = new DataSet("TABLE");
set.Tables.Add(table1);
DgGrid.ItemsSource = set.Tables["Customers"].DefaultView;

}

}

Comments (3)

Answer - Posted 10 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hi Soraya,

The XPath and YPath attributes shouldn't be bindings, they should be string paths instead.  You would want XPath="Name" and YPath="No1" instead.  Also you probably don't want that YAxis setter in there since it doesn't look valid.

That being said, I'm not sure that our product supports binding to tables at this time.  You aren't binding the series to any data in the code above and would need to set your AreaSeries.ItemsSource to a List<Customer> where Customer is a custom class with Name and No1 properties.  If you do those things, it will definitely work.


Actipro Software Support

Posted 10 years ago by Soraya
Avatar

Hi,

Here is my code for new example as you said,but it still does not show any result.

Thanks,

Soraya

 

<DockPanel>
<charts:XYChart x:Name="XyChart">
<charts:AreaSeries x:Name="AreaSeries" XPath="Name" YPath="Value"/>
</charts:XYChart>
</DockPanel>

 

 

public MainWindow()
{
InitializeComponent();

ChartObjekte = new List<ChartObjekt>();
ChartObjekte.Add(new ChartObjekt { Name = "Sam", Value = 1 });
ChartObjekte.Add(new ChartObjekt { Name = "Mark", Value = 2 });
ChartObjekte.Add(new ChartObjekt { Name = "Norah", Value = 3 });
ChartObjekte.Add(new ChartObjekt { Name = "Max", Value = 4 });

AreaSeries.ItemsSource = ChartObjekte;
}

Posted 10 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hi Soraya,

I pasted that code in a simple project here (also made the ChartObjekt class) and it worked fine for me.  I see the chart render ok.

I wonder if your chart isn't getting any size based on the panels that contain it?  Maybe set a MinWidth/MinHeight or Width/Height and see if that gets it to show up.  If not, please make a new simple sample project that shows the issue and email it to our support email address and we will debug it.  Be sure to reference this thread and rename the .zip file extension of anything you send so it doesn't get spam blocked.


Actipro Software Support

The latest build of this product (v24.1.1) was released 1 month ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.