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. (Last updated on: June 24, 2019).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Using Javascript to Set the Datasource for a Sparkline

Thread ID:

Created:

Updated:

Platform:

Replies:

142602 Feb 12,2019 01:39 AM UTC Feb 13,2019 11:45 AM UTC ASP.NET MVC - EJ 2 1
loading
Tags: Sparkline
Lance Harwell
Asked On February 12, 2019 01:39 AM UTC

I have a javascript interval that periodically changes (not refresh but completely change) the datasource for all controls on the page. I have a 3 sparklines that I need to change datasources for as well but I've yet to find an example of how to deal with them using javascript. Can you please help?


Dharanidharan Dharmasivam [Syncfusion]
Replied On February 13, 2019 11:45 AM UTC

Hi Lance, 
 
Greetings from Syncfusion.  
 
We have analyzed the enquired requirement. We have prepared a sample in which we have updated the data source for every 3 seconds using setInterval method of Javascript method. Find the code snippet below to achieve this. 
 
function update() { 
        setInterval(function () { 
 
            Getting instance of chart 
            var spark1Obj = document.getElementById('spark1').ej2_instances[0], 
             //... 
            Assigned data soruce 
            spark1Obj.dataSource = [{ xval: 'X1', yval: Math.floor(Math.random() * 6) + 1 }, 
                //...] 
            Refreshed the sparkline using refresh method 
            spark1Obj.refresh(); 
             //... 
        }, 3000); 
    } 
 
 
Screenshot: 
Before Refreshing: 
 
After Refreshing: 
 
 
Here we have changed the data source alone. You can change this based on your scenario. Sample for reference can be found below. 
 
Thanks, 
Dharani. 


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile
Live Chat Icon