0

Does anyone know if I can use the High Charts speed o meter with Ajax calls? I was thinking in the following function putting the call in where I point out. But I know sometimes this types of graphs, charts, meters don't like Ajax calls.

  // Add some life
function (chart) {
    setInterval(function () {
        var point = chart.series[0].points[0],
            newVal,
            inc = **Ajax call here**;

        newVal = point.y + inc;
        if (newVal < 0 || newVal > 20) {
            newVal = point.y - inc;
        }

        point.update(newVal);

    }, 3000);

In fact I really don't need an Ajax call within the function. I just need an Ajax call to the server, check to see if it's 'squaking' if it is use a Boolean set that to true and then use a random number between say 1-20, and if it's not just set the function to output 0;.

It's essentially a bandwidth meter so to speak, I'm just wondering if it's possible with this meter before I spend 5 hours on it for nothing if it's not possible. Can anyone give suggestions?

Here is the meter in JSFiddle where I'm currently messing around with it.

http://jsfiddle.net/gh/get/jquery/1.7.2/highslide-software/highcharts.com/tree/master/samples/highcharts/demo/gauge-speedometer/

Mallikarjuna Reddy
  • 1,212
  • 2
  • 20
  • 33
John Verber
  • 745
  • 2
  • 16
  • 31

1 Answers1

2

Certainly you can

setInterval(function () {
    var point = chart.series[0].points[0],
        newVal,
        inc = 0;

    $.get('squaking', function (data) {
        newVal = point.y + data.inc;
        if (newVal < 0 || newVal > 20) {
            newVal = point.y - data.inc;
        }

        point.update(newVal);
    });
}, 3000);

I'm assuming here that "squaking" is a server side function that returns a JSON result containing a value for inc. Once the data is returned, the chart is then updated.

Lydon
  • 2,942
  • 4
  • 25
  • 29
  • Yeah you hit the nail on the head. Do I have to use json ? Or can I just have some values within a text file? If I have to use json, do you happen to know where I could learn how to write a json file? I know how to grab json data from a file but never really have written data into a file. Thanks. – John Verber Mar 15 '13 at 06:16
  • Absolutely not. You can use anything you like. I just used $.get returning JSON as an example but it all depends on what the server side function returns. "data" could be json, html, text, xml etc. – Lydon Mar 15 '13 at 06:42
  • Cool...I actually don't need to return data. I just need to make a call to the server to see that it's returning 4 and 200...then I can use any interger between 1 and 20...if not use zero showing that the server is down. Essentially a bandwidth meter but not true data...thanks for the help! – John Verber Mar 15 '13 at 07:04