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

real timpe ploting in xamarin.forms

hello,I'm writing a program that receives  values from a list and combine it with real time and makes an observableobject  list. but the ptoblem is I want that any 0.5 milliseconds creates a new value on chart. but the function addmillisecond() only takes integers. what should I do?
heres the code:

class viewModel
    {
        public ObservableCollection data { get; set; }
        List values;

        DateTime datetimes;
        public viewModel()
        {
            data = new ObservableCollection();
            values = new List()
            {
                    6.3507080e-02,
                     6.6223145e-02,
                     6.1676025e-02,
                     5.6243896e-02,
                     5.0811768e-02,
                     5.5328369e-02,
                     7.1655273e-02,
                     5.6243896e-02,
                     3.6010742e-03,
                    -2.2674561e-02,
                    -7.2326660e-03,
                     8.8500977e-04,
                    -1.8005371e-03,
                    -1.8005371e-03,
                    -8.1481934e-03,
                    -1.3610840e-02,
                    -2.7160645e-03,
                    ...
                    };
               datetimes = new DateTime(0);

            for (int i = 0; i < 1000; i++)
            {
                data.Add(new model(values[i], datetimes));
                datetimes = datetimes.AddMilliseconds(1);
            }

            LoadData();
        }

        public void LoadData()
        {
            bool val = true;
            int counter = 1001;
            Device.StartTimer(new TimeSpan(0, 0, 0, 0, 50), () =>
            {
                for (int n = 0; n <= 49; n++)
                {
                    data.RemoveAt(n);
                    if (counter == values.Count)
                    {
                        val = false;
                        break;
                        
                    }
                    data.Add(new model(values[counter], datetimes));
                    counter++;
                    datetimes = datetimes.AddMilliseconds(1);
                }
                return val;
            });
        }
    }


3 Replies

BK Bharathiraja K Syncfusion Team April 17, 2019 10:31 AM UTC

Hi Mohamad, 
 
Greetings from Syncfusion. 
 
Yes, the method DateTime.AddMilliseconds(Double) rounded the millisecond to nearest integer, as by the .Net documentation we can use DateTime.AddTicks (Double) method. One Millisecond = 10,000 ticks. So, we can add 5000 ticks for half millisecond. Even though the millisecond will always be rounded to nearest possible integer. We don’t have any other chance.  
.Net documentation: How_to_Add_Milisecond & How_to_Add_ticks 
 
 
 
Regards, 
Bharathi. 



MO mohamad replied to Bharathiraja K April 17, 2019 06:35 PM UTC

Hi Mohamad, 
 
Greetings from Syncfusion. 
 
Yes, the method DateTime.AddMilliseconds(Double) rounded the millisecond to nearest integer, as by the .Net documentation we can use DateTime.AddTicks (Double) method. One Millisecond = 10,000 ticks. So, we can add 5000 ticks for half millisecond. Even though the millisecond will always be rounded to nearest possible integer. We don’t have any other chance.  
.Net documentation: How_to_Add_Milisecond & How_to_Add_ticks 
 
 
 
Regards, 
Bharathi. 


thanks a lot man


BK Bharathiraja K Syncfusion Team April 18, 2019 05:04 AM UTC

Hi Mohamad,  
 
Thanks for your feedback. 
 
-Bharathi. 


Loader.
Live Chat Icon For mobile
Up arrow icon