Jump to content
Software FX Community

Duplicating pie charts on postbacks? What's happening?


LSUgirl

Recommended Posts

Hi,

I have a single pie chart my page with some date range text boxes.  The user enters a date range and it populates the pie chart.  If the user selects another date range, it retrieves the data and creates a chart with 2 pie charts.  If the users searches again, I get 3 pie charts.  And so on.  What is going on?  The ldt is always created with one set of 7 rows.  It's not a data issue.

 My code behind:

 

Chart1.Data.Clear();

DataTable ldt = iPDDataAdapterTop5.RetrievePBToDt(0);

// if table has label, value, value use thisChart1.DataSourceSettings.Fields.Add(new FieldMap("code_desc", FieldUsage.Label));

Chart1.DataSourceSettings.Fields.Add(

new FieldMap("per_stds", FieldUsage.Value));Chart1.DataSourceSettings.Fields.Add(new FieldMap("nbr_stds", FieldUsage.NotUsed));

Chart1.DataSourceSettings.DataSource = ldt.DefaultView;

 

// do this to make mapping workSystem.IO.MemoryStream objStream = new System.IO.MemoryStream();

Chart1.Export(ChartFX.WebForms.

FileFormat.Jpeg, objStream);

Chart1.DataBind();

Link to comment
Share on other sites

this code should be withing:

if (!IsPostBack) {

}

Otherwise you will be executing it every time a clallbsack/postpack occurs. In particular the problem is with the Fields collection. You are adding to it every time. If you want to start fresh you must do:

Chart1.Fields.Clear();

However, the IsPostBack check is a better option. You don't need to be doing any databinding again unless you need to.

Link to comment
Share on other sites

Archived

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

×
×
  • Create New...