0

I am trying to create a web app for Data charting component using Envision.js. The data being used is a Stock Price Ticker feed in JSON format. I have formed a standard finance line chart (Envision Finance template) using ajax jquery call for getting ticker data and applying the data in the X-Y axis.

But requirement is to create a realtime chart which will update automatically over time with the Stock data with all the child graph details. Below is the code for the stock chart application :

(function ajax_demo (container) {

  // Get initial data
  $.getJSON('static/stockTicker.json', function (initialData) {
    var
      currentData = initialData,
      options, finance;

    options = {
      container : container,
      data : {
        price : currentData.price,
        volume : currentData.volume,
        summary : currentData.summary
      },
      trackFormatter : function (o) {

        var
          index = o.index,
          value;

        value = currentData.data[index].date + ': $' + currentData.price[index][1] + ", Vol: " + currentData.volume[index][1];

        return value;
      },
      // An initial selection
      selection : {
        data : {
          x : {
            min : 0,
            max : 250
          }
        }
      },
      // Override some defaults.
      // Skip preprocessing to use flotr-formatted data.
      defaults : {
        volume : {
          skipPreprocess : true
        },
        price : {
          skipPreprocess : true
        },
        summary : {
          skipPreprocess : true,
          config : {
            xaxis : {
              // Set x ticks manually with defaults override:
              ticks : currentData.summaryTicks
            }
          }
        }
      }
    };

    // Set the selection callback:

    options.selectionCallback = (function () {

      var data = {
        initial : initialData,
        fetched : null
      };

      // Helper for fetching high resolution data
      function fetchData (o) {
        $.getJSON('static/stockSample.json', function (fetchedData) {
          data.fetched = fetchedData;
          currentData = fetchedData;
          finance.price.options.data = data.fetched.price;
          finance.volume.options.data = data.fetched.volume;
          _.each(finance.selection.followers, function (follower) {
            follower.trigger('zoom', o);
          }, this);
        });
      }

      // Selection callback:
      return function (selection) {

        if (finance) {
          var
            x = selection.data.x;

          if (x.max !== null && Math.abs(x.max - x.min) < 250) {
            if (data.fetched) {

              // Use high resolution data, if available
              finance.price.options.data = data.fetched.price;
              finance.volume.options.data = data.fetched.volume;
              currentData = data.fetched;
            } else {

              // Fetch high resolution data
              fetchData(selection);
            }
          } else {

            // Use low resolution data
            finance.price.options.data = data.initial.price;
            finance.volume.options.data = data.initial.volume;
            currentData = data.initial;
          }
        }
      }
    })();

    finance = new envision.templates.Finance(options);
  });
}
)(document.getElementById("Demo")); 

I couldn't get any example where we can integrate a stock chart in Envision.js with dynamic stock price data updated with specific time. Shall I use Spring mvc or normal servlet to get it working?

Please help!

maali
  • 134
  • 3
  • 14

1 Answers1

0

You may use the feature "Refresh after a particular time interval".

Aman Jain
  • 655
  • 5
  • 17