LSUgirl Posted August 6, 2007 Report Share Posted August 6, 2007 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(); Quote Link to comment Share on other sites More sharing options...
Frank Posted August 6, 2007 Report Share Posted August 6, 2007 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.