How to create a StripChart

Thread is closed for posting
3 posts, 0 answers
  1. Marc
    Marc avatar
    17 posts
    Member since:
    May 2009

    Posted 20 May 2010 Link to this post

    I would like to create a dynamic strip chart using RadChart.

    Chart type is Line
    The x-axis should be a time axis showing the time of the last update

    After filling the x-axis I would like to drop the oldest point and add a new point to the end of the chart

    This sample code adds the new item to the chart but how would I add x-axis (time) labels for each new item?
               if (Session["rtvals"] == null
                Session["rtvals"] = DateTime.Now.Second; 
                else 
                Session["rtvals"] = Session["rtvals"] + "," + DateTime.Now.Second; 
     
                String[] vals = Session["rtvals"].ToString().Split(','); 
                for (int i = 0; i < vals.Length; i++) 
                { 
                    Chart5.Series[0].AddItem(Convert.ToDouble(vals[i])); 
                } 

    Thanks

    Marc
  2. Marc
    Marc avatar
    17 posts
    Member since:
    May 2009

    Posted 20 May 2010 Link to this post

    I have changed my code to the following:

    This code adds the current time to the XVALUE which is incremented by 30 seconds but the chart is
    plotting points at the same x-axis time (see attached image).

           Chart5.PlotArea.XAxis.AutoScale = false
                Chart5.PlotArea.YAxis.IsZeroBased = true
     
                if (Session["rtstime"] == null) Session["rtstime"] = DateTime.Now; 
     
                if (Session["rtvals"] == null
                Session["rtvals"] = DateTime.Now.Second; 
                else 
                Session["rtvals"] = Session["rtvals"] + "," + DateTime.Now.Second; 
     
                const double hourStep = 1 / 24.0; 
                const double secondStep = hourStep / 3600; 
                const double thirtysecondStep = secondStep * 30; 
     
                double startTime = Convert.ToDateTime(Session["rtstime"]).ToOADate(); 
                double endTime = DateTime.Now.ToOADate(); 
     
                Chart5.PlotArea.XAxis.AddRange(startTime, endTime, 3600/30); 
                String[] vals = Session["rtvals"].ToString().Split(','); 
                int i=0; 
                for (double currentTime = startTime; currentTime < endTime; currentTime += thirtysecondStep) 
                { 
                    ChartSeriesItem item = new ChartSeriesItem(); 
                    item.XValue = currentTime; 
                    item.YValue = Convert.ToDouble(vals[i]); 
                    Chart5.Series[0].Items.Add(item); 
                    i++; 
                } 

    What am I doing wrong???
  3. Ves
    Admin
    Ves avatar
    2926 posts

    Posted 25 May 2010 Link to this post

    Hello Marc,

    The OLEAutomation DateTime equivalent (which is used in RadChart, retrieved by the DateTime.ToOADate method) represents one day as the number one. So this line:
    Chart5.PlotArea.XAxis.AddRange(startTime, endTime, 3600/30);
    sets a step which is 120 days.  I am not sure if this is the expected setting. In addition, I can see that on initial load, when Session["rtstime"] is not set, the start and end values will be very close or identical -- both are set to DateTime.Now.ToOADate(). Please, check these and let us know if the issue remains.

    Best regards,
    Ves
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
Back to Top