SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Evangelist
    Join Date
    Jan 2005
    Location
    UK
    Posts
    539
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Use settimeout to auto-refresh chart?

    I have a chart in Highcharts that loads data from an ajax call. All fine, except I would like it to reload every 10 seconds?
    Here's the main part of the js:

    $(function() {

    $.getJSON('mychart.php', function(arr)
    {

    chart = new Highcharts.Chart({
    chart: {
    renderTo: 'container',
    defaultSeriesType: 'area',
    zoomType: 'x',
    spacingTop: 2,
    spacingRight: 10,
    spacingLeft: 2,
    spacingBottom: 10
    },

    ... and so on ....

  2. #2
    SitePoint Addict
    Join Date
    Apr 2011
    Posts
    266
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Hi
    You can add the Highcharts.Chart into a function, then call the function with setInterval('function_name()', 10000).
    Code:
    function function_name() {
    $.getJSON('mychart.php', function(arr)
    {
    
    chart = new Highcharts.Chart({
    chart: {
    renderTo: 'container',
    defaultSeriesType: 'area',
    zoomType: 'x',
    spacingTop: 2,
    spacingRight: 10,
    spacingLeft: 2,
    spacingBottom: 10
    },
    
    //... and so on ....
    }
    
    function_name();
    setInterval('function_name()', 10000);
    Free: Web Programming Courses HTML, CSS, Flash
    Web Programming: AJAX Course and PHP-MySQL Course video Lessons
    Good JavaScript and jQuery course for beginners


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •