We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
close icon

Chart populates from Dropdown but after selection and postback no data displayed

Hi,

After trying to implement the sample located here:


I can populate the chart on Page_Load but when a selection is made, no data is displayed. I can't see where my code differs from the example. Could you offer some assistance or advice?

Thanks,

Alex

Attachment: PlanningAnalysis_2af68626.zip

3 Replies

BP Baby Palanidurai Syncfusion Team May 6, 2019 11:15 AM UTC

Hi Alex, 
 
Greetings from Syncfusion. 
 
We have analysed your query with the attached sample and code snippet. From that, we suspect that issue is occurred due to data not bind to the chart when isPostBack value as true. We have prepared a sample based on your requirement. In that, we have used the dropdown to call Page_Load and refresh the chart based on postback condition. The chart is working fine. Please find below code snippet and sample, 
 
Code Snippet: 
[ChartFeatures.aspx.cs]: 
protected void Page_Load(object sender, EventArgs e) 
        { 
            if (!IsPostBack) 
            { 
                this.bindChartData(); 
            } 
            else 
            { 
                //other configurations here 
                this.Chart1.DataSource = data; 
                this.Chart1.DataBind(); 
            } 
            } 
        private void bindChartData() 
        { 
            Series series1 = new Series(); 
            Series series2 = new Series(); 
            List<ChartSqlData> data = new List<ChartSqlData>(); 
            string connectionString = null; 
            SqlDataAdapter adapter = new SqlDataAdapter(); 
            DataSet dataset = new DataSet(); 
            connectionString = @"Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=|DataDirectory|\NORTHWND.MDF;Integrated Security=True;User Instance=false;Connect Timeout=100;"; 
            SqlConnection con = new SqlConnection(connectionString); 
            con.Open(); 
 
            string command2 = "SELECT * FROM [Products] WHERE UnitPrice < 10"; 
            SqlCommand cmd1 = new SqlCommand(command2, con); 
            adapter.SelectCommand = cmd1; 
            adapter.Fill(dataset); 
            for (var i = 0; i < dataset.Tables[0].Rows.Count; i++) 
            { 
                string x1 = Convert.ToString(dataset.Tables[0].Rows[i]["ProductName"]); 
                double y1 = Convert.ToDouble(dataset.Tables[0].Rows[i]["UnitPrice"]); 
                double y2 = Convert.ToDouble(dataset.Tables[0].Rows[i]["UnitsInStock"]); 
                data.Add(new ChartSqlData(x1, y1, y2)); 
            } 
            this.Chart1.DataSource = data; 
            this.Chart1.DataBind(); 
        } 
        protected void TradesDropDown_ValueSelect(object sender, Syncfusion.JavaScript.Web.DropdownListEventArgs e) 
        { 
            Session["ShipCity"] = e.Value; 
        } 
 
 
 
Kindly check the sample and revert us still you have face any problems. 
 
Regards, 
Baby. 



AJ Alex Jermy May 7, 2019 08:28 AM UTC

Hi,

I'm just looking at the example and I am slightly confused by how the 'selected' string is used? 

What I am trying to do is to use the value selected on the Drop Down List in order to populate the 3 charts. What I think your sample shows is a Drop Down List where the value of the Drop Down is stored as a session variable - but I don't think that session variable is being used to populate the chart?

Sorry for the confusion I just think that variable is not being used in the way I am hoping to use it?

Thanks,

Alex


BP Baby Palanidurai Syncfusion Team May 7, 2019 01:42 PM UTC

Hi Alex, 
 
Sorry for the inconvenience caused. 
 
In our previous update, we didn’t use selected value anywhere. As stated earlier, when selection is made every time Page_Load is called. That’s why the empty chart is rendered. So we suggest binding chart data source inside of dropdown value select event. In this case, page_Load is called after chart data source is bind to the chart. Also, we are confused from your code snippet what is your exact requirement to use button click. Please revert us with more information about the use case of button click in your sample which is more helpful for further analysis. We have modified an already provided sample based on your requirement. In that chart is working fine based on the selection. 
 
Code Snippet: 
[ChartFeatures.aspx.cs]: 
protected void Page_Load(object sender, EventArgs e) 
        { 
            if (!IsPostBack) 
            { 
                this.bindChartData(); 
            } 
 
        } 
        protected void TradesDropDown_ValueSelect(object sender, Syncfusion.JavaScript.Web.DropdownListEventArgs e) 
        { 
            Session["UnitPrice"] = e.Value; 
            string selected = Session["UnitPrice"].ToString(); 
            //other configurations here 
            string command2 = "SELECT * FROM [Products] WHERE UnitPrice <" + " " + selected; 
            SqlCommand cmd1 = new SqlCommand(command2, con); 
            adapter.SelectCommand = cmd1; 
            adapter.Fill(dataset); 
            for (var i = 0; i < dataset.Tables[0].Rows.Count; i++) 
            { 
                string x1 = Convert.ToString(dataset.Tables[0].Rows[i]["ProductName"]); 
                double y1 = Convert.ToDouble(dataset.Tables[0].Rows[i]["UnitPrice"]); 
                double y2 = Convert.ToDouble(dataset.Tables[0].Rows[i]["UnitsInStock"]); 
                data.Add(new ChartSqlData(x1, y1, y2)); 
            } 
            this.Chart1.DataSource = data; 
            this.Chart1.DataBind(); 
            //other configurations here 
       } 
 
 
Kindly check the above sample and revert us, if you need further assistance. 
 
Regards, 
Baby. 


Loader.
Live Chat Icon For mobile
Up arrow icon