Bar chart will not render with date change

Thread is closed for posting
3 posts, 0 answers
  1. Rick
    Rick avatar
    3 posts
    Member since:
    Mar 2013

    Posted 27 Mar 2013 Link to this post

    I have a programmatically rendered chart getting its information from Telerik date controls and dropdown. When I set date controls and drop downs to their values, the chart renders correctly. When I change the date and click my button to render the chart again, the chart maintains the previous informaiton. I debugged the code and the sql is getting the correct dates but the chart is still rendering the previous dates. Any thing I am missing here regarding the rendering process?
  2. Achilles
    Achilles avatar
    57 posts
    Member since:
    Jan 2013

    Posted 27 Mar 2013 Link to this post

    Is your chart Ajax bound ? What exactly do you do when you click the button to render the chart ? Do you call a rebind or a refresh ?
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Rick
    Rick avatar
    3 posts
    Member since:
    Mar 2013

    Posted 28 Mar 2013 Link to this post

    The chart is Programmatically created. When I switch the date it will not reference the sql query. My Code:
    protected void GetOperators()
            {
                ArrayList operators = new ArrayList();
                DataProvider d = new DataProvider();
                DataTable dt = new DataTable();
            
                RadChart radchart = new RadChart();
                
                radchart.Clear();
                radchart.Skin = "Desert";
                radchart.PlotArea.XAxis.Visible = Telerik.Charting.Styles.ChartAxisVisibility.True;
                radchart.Width = 1500;
                radchart.PlotArea.DataTable.Visible = true;
                radchart.ChartTitle.TextBlock.Text = "Pieces Per Operator";
     
                //get dates for the chart
                DateTime Start =  Convert.ToDateTime(RadDatePicker1.SelectedDate);
                DateTime End =  Convert.ToDateTime(RadDatePicker2.SelectedDate);
                DateTime CounterDate;
     
                double average = 0;
     
                string startDate = RadDatePicker1.SelectedDate.Value.ToShortDateString();
                string endDate = RadDatePicker2.SelectedDate.Value.ToShortDateString();
                string shift = ddl_shift.SelectedValue.ToString();
                string machineId = DropDownList1.SelectedValue.ToString();
                string oper = "";
                string sql = "";
                string theDate;
                int efficiency = 0;
     
     
                TimeSpan t = End - Start;
                int diff = t.Days;
     
                
     
                //the operators during shift on machine during time frame
                operators = d.GetOperator(startDate, endDate, machineId, shift);
     
                for (int i = 0; i <= operators.Count - 1; i++)
                {
                    radchart.Series.Add(new ChartSeries(operators[i].ToString(), ChartSeriesType.Bar));
                }
            
              
                //loop for the date
                for (int j = 0; j <= diff; j++)
                {
     
                    CounterDate = Start.AddDays(j);
     
     
                    //loop for operators
                for (int i = 0; i <= operators.Count - 1; i++)
                {
     
                   radchart.Series[i].Appearance.LabelAppearance.Visible = true;
                   radchart.Series[i].Appearance.LineSeriesAppearance.Color = System.Drawing.Color.Beige;
                   
                   //select from operator, machine, and date
                   oper = operators[i].ToString();
                    
                   startDate = CounterDate.ToShortDateString();
     
     
                     
                    sql = "SELECT Machines.MachineEff, Format(Master.PDate,'mm/dd')  as [Date], Master.ActQuan, Master.Hours, IIf([Master].[Hours]=0,0,Round(([Master].[ActQuan]/[Master].[Hours]))) AS [AVG], Operators.OperLastName, Machines.MachineName, Master.PDate FROM (Machines RIGHT JOIN Orders ON Machines.Mach_ID = Orders.OrdMachID) LEFT JOIN (Operators RIGHT JOIN Master ON Operators.Op_ID = Master.Operator) ON Orders.Ord_ID = Master.Master_OrdId WHERE (((Operators.OperLastName)=" + "'" + oper + "'" + ") AND ((Machines.MachineDisable)=False) and ((Machines.Mach_Id)="  + machineId +  ") AND ((Master.PDate)=#" + startDate + "#))";
     
                    dt= d.GetTable(sql);
     
     
                    if (dt.Rows.Count > 0)
                    {
                        average = Convert.ToDouble(dt.Rows[0]["AVG"]);
                        theDate = dt.Rows[0]["Date"].ToString();
                       
                    }
                    else
                    {
     
     
                        theDate = CounterDate.ToString("MM") + "/" + CounterDate.Day;
                        average = 0;
                    }
     
                    //{
                        //if (dt.Rows[0]["AVG"].ToString() != "0")
                        //{
     
     
                        //get the count of pieces
                        radchart.Series[i].AddItem(average);
     
                        radchart.Series[i].Appearance.PointMark.Dimensions.AutoSize = false;
                        radchart.Series[i].Appearance.PointMark.Dimensions.Width = 5;
                        radchart.Series[i].Appearance.PointMark.Dimensions.Height = 5;
                        radchart.Series[i].Appearance.PointMark.FillStyle.MainColor = System.Drawing.Color.Black;
                        radchart.Series[i].Appearance.PointMark.Visible = true;
                        radchart.Series[i].Appearance.ShowLabels = true;
     
     
                        if (i <= 0)
                        {
                            radchart.PlotArea.XAxis.AutoScale = false;
     
                            
     
                            radchart.PlotArea.XAxis.Items.Add(new ChartAxisItem(theDate));
     
                            radchart.PlotArea.XAxis.AutoScale = false;
                        }
                        //}
                    //}
                }
     
                }
                //trend line
                efficiency = Efficiency();
     
                
     
                Telerik.Charting.ChartMarkedZone trendLine = new Telerik.Charting.ChartMarkedZone();
                trendLine.ValueStartY = efficiency;
                trendLine.ValueEndY = efficiency + 100;
     
     
                trendLine.Appearance.FillStyle.MainColor = System.Drawing.Color.Green;
     
                radchart.PlotArea.MarkedZones.Add(trendLine);
                 
     
                this.Page.Controls.Add(radchart);
     
            }
     
            protected void LinkButton1_Click(object sender, EventArgs e)
            {           
                GetOperators();
             }
            }
Back to Top