I use a Shield UI Chart for displaying some forex data. I do need to gradually add data to the chart in other dynamically add points.
However according to the documentation, there isn’t the possibility for dynamically adding of points, at least I can’t see such method, something like: AddPoint or similar.
How can I still achieve a web page using Shield UI Chart, which to constantly show a couple of exchange rates?

Recommended Answers

All 2 Replies

If they don't support it, then only refreshing the chart can work (but not recommended). However, I think this question is more suited to be asked to Shield support.

You are right, that there is no addPoints method of the Shield UI Chart. However we can add the incoming data values to an array instead. You might find useful following code:
1. We need some arrays- as many as we need to show.

            var EURUSD = new Array();
            var USDCAD = new Array();
            var GBPUSD = new Array();
  1. In the body of the function, that will actually display the data we will have the following code:

    EURUSD[EURUSD.length] = parseFloat(data.ticks.EURUSD);
    USDCAD[USDCAD.length] = parseFloat(data.ticks.USDCAD);
    GBPUSD[GBPUSD.length] = parseFloat(data.ticks.GBPUSD);

it will actually put the new data to the designated arrays. You can note, that each time data is received, it has been added to the last index of each array: EURUSD.length

  1. Since we don’t want our arrays to grow too large, it is good to specify how many points we need to keep. Once that limit is reached, we remove the oldest point:

    if (EURUSD.length > 50)
    EURUSD = EURUSD.splice(1, 49);

    if (USDCAD.length > 50)
    USDCAD = USDCAD.splice(1, 49);

    if (GBPUSD.length > 50)
    GBPUSD = GBPUSD.splice(1, 49);

  2. At the end we need to recreate the chart, referencing the appropriate container:

    var containter = $("#EURUSDChart").swidget();

and than create the chart again.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.