Jump to content
Software FX Community

How to remove columns using DataSourceSettings.Fields collection


eric.m.smith

Recommended Posts

I have a DataTable that I am trying to filter to display multiple pie charts from one set. I am able to filter my data using a DataView but once the data is assigned to the Chart, I want to remove the filtered column from the bound fields. I want to do this because the filtered data is being used as labels when I want other fields from the dataview.

 In my sample code below. I want to remove the "REGION" column so that my labels are pulled from the "TYPE" column. If I try to do this by removing the REGION from usage, the chart displays no data. How can I do this? Is there a completely different approach to doing this in the chart? I know i can do this my manually building a new Data Table that doesnt contain the "REGION" column, but it looks like the chart should be able to exclude the column for me.

 Thanks - Eric Smith 

 [replace page_load of a blank aspx page to run the code]

  protected void Page_Load(object sender, EventArgs e)   {   ChartFX.WebForms.Chart cht = new ChartFX.WebForms.Chart();   cht.Gallery = ChartFX.WebForms.Gallery.Pie;   System.Data.DataTable dt = new DataTable();   dt.Columns.Add("REGION", System.Type.GetType("System.String"));   dt.Columns.Add("TYPE", System.Type.GetType("System.String"));   dt.Columns.Add("PCT", System.Type.GetType("System.Int16"));   dt.Rows.Add(new object[] { "R1", "O", 20 });   dt.Rows.Add(new object[] { "R1", "W", 80 });   dt.Rows.Add(new object[] { "R2", "O", 50 });   dt.Rows.Add(new object[] { "R2", "W", 50 });     //cht.DataSourceSettings.Fields.Add(new ChartFX.WebForms.FieldMap("REGION", ChartFX.WebForms.FieldUsage.NotUsed));   cht.DataSource = new System.Data.DataView(dt, "REGION='R1'", "", DataViewRowState.CurrentRows);   form1.Controls.Add(cht);   } 

Link to comment
Share on other sites

If there is no elegant way to do this using the ChartFX API you may want to consider:

Filtering the data in DataView #1

Pushing DataView #1 to new DataTable #2

Removing the columns you don't want from DataTable #2

Creating DataView #3 based on DataTable #2

Binding DataView #3 to the chart (or you could skip this step and bind DataTable #2)

Definitely a kludge but it will work.

Link to comment
Share on other sites

cht.DataSourceSettings.Fields is empty by default.

If at the time of DataBinding, the Fields collection is empty, the fields collection is read from the schema.

If you want only a few fields to be display you must Add (not remove) these to the Fields collection. You add the ones you want (as opposed to removing those you don't).

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...