Jump to content
Software FX Community

Bind CrosstabTransform to DataTable


octa

Recommended Posts

I'm trying to use a CrosstabTransform with a c# DataTable as a source. Is there any example of how to do this?

Binding the ItemsSource of the Chart to the DataTable seems to work but the issue I'm having is setting up the row, column and value path. It doesn't seem to work with the columns of the Dataset. Is there any syntax example?

 Thanks,

Dan

 

Link to comment
Share on other sites

Hi,

I created this sample from a  DataTable, however if you are using a DataSet lets say called ds, just set DataTable table1 = ds.Tables[0];

  DataTable table1 = new DataTable();   DataColumn nameColumn = new DataColumn("Name", typeof(string));   DataColumn yearColumn = new DataColumn("Year", typeof(int));   DataColumn valueColumn = new DataColumn("Value", typeof(double));   table1.Columns.Add(nameColumn);   table1.Columns.Add(yearColumn);   table1.Columns.Add(valueColumn);   DataRow row1 = table1.NewRow();   row1["Name"] = "Product A";   row1["Year"] = 2006;   row1["Value"] = 15452;   DataRow row2 = table1.NewRow();   row2["Name"] = "Product B";   row2["Year"] = 2007;   row2["Value"] = 25652;   DataRow row3 = table1.NewRow();   row3["Name"] = "Product C";   row3["Year"] = 2008;   row3["Value"] = 33351;   table1.Rows.Add(row1);   table1.Rows.Add(row2);   table1.Rows.Add(row3);   CrosstabTransform crosstab = new CrosstabTransform();   crosstab.ColumnPath = "Year";   crosstab.RowPath = "Name";   crosstab.ValuePath = "Value";   chart1.DataTransforms.Add(crosstab);   chart1.ItemsSource = table1.DefaultView;

I used DefualtView, since the ItemSource needs an object that implements IEnumerable.

Hope this helps.

Link to comment
Share on other sites

It looks like the databinding works now. I'm trying to do a pane matrix just like in the sample project "Pane Matrix". But even though I've got several columns listed in the column path of the crosstabtransform object there are no dimensions being created. Is there anything special that has to be done in order to get the dimensions created?

 

Thanks,

Dan

Link to comment
Share on other sites

Thanks! I've compared your sample with my code and the only difference I see is that the ItemsSource on the chart is not set directly in code behind but by databinding in XAML. Then in the code behind I have to wait for the UserControl Loaded event before I set up the CrosstabTransform in code behind. It uses two different columns in the columns field but still wont create any dimensions. I've checked and there clearly is a working ItemsSource with data values and all column names are spelled right and the value path is of type double. I'll copy in some code here just in case you are able to spot something wrong with it:

private void UserControl_Loaded(object sender, RoutedEventArgs e)

{

 

LoadData();

SetUpMatrix();

}

private

void LoadData()

{

crosstab = new CrosstabTransform();

crosstab.ColumnPath = "Calendar,Country";

crosstab.RowPath =

"Group";crosstab.ValuePath = "Internet";

crosstab.JoinOnColumns =

true;crosstab.SortRows = true;

chart.DataTransforms.Add(crosstab);

}

private void SetUpMatrix()

{

GridPanePanel gridPanePanel = new GridPanePanel();

gridPanePanel.Columns = crosstab.Dimensions[0].Count;

This is where it breaks when no dimensions get created.

 

Thanks,

Dan

Link to comment
Share on other sites

 Try to call the Load Data at the usercontrol loaded and the SetUpMatrix() method at the Chart Loaded event like this:

 

 public Window1()
  {
  InitializeComponent();
  LoadData()
  chart1.Loaded += new RoutedEventHandler(chart1_Loaded);
  }

  void chart1_Loaded(object sender, RoutedEventArgs e)
  {
  // Once the chart is rendered.
  SetUpMatrix();
  }

post-2986-13922413084889_thumb.png

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...