Click here to Skip to main content
15,884,177 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I have created a user control which has a chart to display employee statistics over a period of time. I have used MSChart. I have 3 different series and i want to switch between them at runtime so that the user has an option to view different statistics. I have used legenditem and using it's postback value, I have parsed it. I have put all of this in an UpdatePanel

The problem is that whenever I click on the legendItem, the control is reloaded and the Chart Area becomes blank. Here is my code. Please help me.

protected void Chart1_Click(object sender, ImageMapEventArgs e)
            // If user clicks on the map area attribute that corresponds to a legend item
            if (e.PostBackValue.StartsWith("LegendClick"))
                string args = e.PostBackValue.Split('/')[1];
                // Identify which legend item was clicked
                int index = int.Parse(args);

                // Legend item result
                LegendItem legendItem = this.Chart1.Legends[0].CustomItems[index];

                // Resets all radio button images to be unchecked
                /* foreach (LegendItem item in this.Chart1.Legends[0].CustomItems)
                     item.Cells[0].ImageTransparentColor = Color.Black;
                     item.Cells[0].Image = "radio_button_unchecked.gif";
                for (; ; )

                    switch (legendItem.Cells[1].Text)
                        case "Points":
                            this.Chart1.Series["series1"].Enabled = true;
                            this.Chart1.Series["series2"].Enabled = false;
                            this.Chart1.Series["series3"].Enabled = false;
                            this.Chart1.Series[0].ChartType = (SeriesChartType)Enum.Parse(typeof(SeriesChartType), "Line", true);
                            this.Chart1.Legends[0].CustomItems[0].Cells[0].Image = "radio_button_checked.gif";

                        case "CSAT":
                            this.Chart1.Series["series1"].Enabled = false;
                            this.Chart1.Series["series2"].Enabled = true;
                            this.Chart1.Series["series3"].Enabled = false;
                            this.Chart1.Legends[0].CustomItems[1].Cells[0].Image = "radio_button_checked.gif";

                        case "SLA":
                            this.Chart1.Series["series1"].Enabled = false;
                            this.Chart1.Series["series2"].Enabled = false; ;
                            this.Chart1.Series["series3"].Enabled = true;
                            this.Chart1.Legends[0].CustomItems[2].Cells[0].Image = "radio_button_checked.gif";

Updated 17-Oct-12 20:51pm
lukeer 18-Oct-12 2:36am    
Use the "Improve question" link just below your question to provied further detail, be it of circumstances, error messages or whatever.

Don't create a new question for that. That way you more likely get a usable answer.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900