Jump to content
Software FX Community

Duplicating pie charts on postbacks? What's happening?


LSUgirl
 Share

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

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.

 Share

×
×
  • Create New...