This is a migrated thread and some comments may be shown as answers.

How to create a StripChart

2 Answers 158 Views
Chart (Obsolete)
This is a migrated thread and some comments may be shown as answers.
Marc
Top achievements
Rank 1
Marc asked on 20 May 2010, 05:02 PM
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 Answers, 1 is accepted

Sort by
0
Marc
Top achievements
Rank 1
answered on 20 May 2010, 05:45 PM
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???
0
Ves
Telerik team
answered on 25 May 2010, 12:23 PM
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.
Tags
Chart (Obsolete)
Asked by
Marc
Top achievements
Rank 1
Answers by
Marc
Top achievements
Rank 1
Ves
Telerik team
Share this question
or