Dynamically updating chart not working


« Back to message list

Enter your email address to get email updates on this topic. You can stop receiving updates by clicking the link in the update email messages.

Posted by Antonio Vianello on 9th July 2013
Hi there!

I'm using a dynamically updating line chart and everything is working fine for the esample given in the documentation.
But if I use the same chart using data from a source that may vary consistently from a minimum to a maximum, the chart doesn't plot anything.

Why this strange behaviour?

Thanks in advance
Posted by RGraph support on 9th July 2013
Hi there,


Since you've given me nothing to go on - I have no idea. Clearly you're not setting the new data correctly. With the Line chart it should be something like this:

myLine.original_data[0] = [4,8,6,5,2,3];

Then you need to redraw the canvas:

RGraph.Redraw();

This demo uses a similar concept:

www.rgraph.net/demos/line-dynamic-updates-range.html

You could try building your page around the example that works.
Richard, RGraph support.
Posted by Antonio Vianello on 9th July 2013
Hi there.

As you suggest, I've slightly modified a working example from yours, but taking values from an AJAX call and redrawing the chart with values returned.

Regardless the other aspects of the code, that, except the AJAX call, is just the same as the original code and that you surely remember, the incredible thing is that sobstituting the working statement

      obj.original_data[0].push(Math.min(value + 5, 50));

with the following
     
      obj.original_data[0].push(value);
         
where value is the value returned from AJAX call, makes the chart not showig any value! I'm sure that the returned values are different from zero but the chart is completely blank and apparently doesn't upgrade itself!

I'm really stuck!

Thanks
Posted by Antonio Vianello on 9th July 2013
Hi there.

As you suggest, I've slightly modified a working example from yours, but taking values from an AJAX call and redrawing the chart with values returned.

Regardless the other aspects of the code, that, except the AJAX call, is just the same as the original code and that you surely remember, the incredible thing is that sobstituting the working statement

      obj.original_data[0].push(Math.min(value + 5, 50));

with the following
     
      obj.original_data[0].push(value);
         
where value is the value returned from AJAX call, makes the chart not showig any value! I'm sure that the returned values are different from zero but the chart is completely blank and apparently doesn't upgrade itself!

I'm really stuck!

Thanks
Posted by Antonio Vianello on 10th July 2013
Hi there!

maybe I've found what's the problem behind.
It seems that RGraph needs to know what is the range of the possible values to correctly draw the line chart. Apparently without those min & max values it cannot figure out where to put the line on the chart.

Does it make sense or my assumption is completely wrong?

Thanks in advance
Posted by RGraph support on 10th July 2013
Hi there,

There's an example here of adding data to the end of the data array:

www.rgraph.net/fiddle/view/1499f436db38ec706dac823477b844a7




Richard, RGraph Support

5 developer license with Priority support for £299:
   www.rgraph.net/license#five-developer
Posted by RGraph support on 10th July 2013
Hi there,

> maybe I've found what's the problem behind.
> It seems that RGraph needs to know what is the range of the possible values to
> correctly draw the line chart. Apparently without those min & max values it cannot
> figure out where to put the line on the chart.
>
> Does it make sense or my assumption is completely wrong?

Not at all - the maximum value is required so that an appropriate scale can be generated. Without it the scale would change and "jump". So you can fix the maximum value with chart.ymax

Richard, RGraph Support

Help support RGraph - single site license only £99!
   www.rgraph.net/license#single-site
Posted by Antonio Vianello on 10th July 2013
Hi there!

So, do you mean that the statement:

obj.original_data[0].push(Math.min(value + 5, 50))

is absolutely required?

Also, in my chart default settings I've already set the chart.ymax value! But despite this the chart with the simple statement:

obj.original_data[0].push(value)

didn't work.

Thanks
Posted by RGraph support on 10th July 2013
Hi there,

Yes the statement is required - you're adding a new value on to the end of the data array.

And in the statement:

obj.original_data[0].push(value)

value needs to be a number - so try casting it as such:

obj.original_data[0].push(Number(value))




Richard, RGraph Support

Help support RGraph - single site license only £99!
   www.rgraph.net/license#single-site
Posted by Antonio Vianello on 10th July 2013
Hi there!

Richard, you unintentionally give me the solution after an entire night of trouble!
What was missing in my case was the cast to a number, that is the statement:

data.push(Number(value)) !!!!

since AJAX returns data by strings, as far as I know...
It was so simple, right?

Ok, it was my fault... :-(

Thanks a lot!
Posted by RGraph support on 10th July 2013
Hi there,

You can use the newer functions to do automatic conversions for you:

RGraph.AJAX.getNumber(url, callback)
RGraph.AJAX.getString(url, callback)
RGraph.AJAX.getCSV(url, callback[, separator])
RGraph.AJAX.getJSON(url, callback)


Richard, RGraph Support

Help support RGraph - single site license only £99!
   www.rgraph.net/license#single-site

Add a reply

 




« Back to message list
RGraph on social media