0

I have a web page with 3 rgraph dynamically updated Line charts. I use ajax call for retrieving data from web service. When ajax call completed with error I want to change the chart background color to 'gray'. And when call is successful to change this color to 'black'.

How to change chart background color dynamically?

I use this code

if(error_occured)
 obj_Memory.Set('background.color', '#B6B6B4');
else
 obj_Memory.Set('background.color', 'black');

But it does not change the color.

I modified rgraph sample:

http://www.rgraph.net/demos/line-dynamic-updates.html

Added button and simple function:

    var error_occured = false;

    document.getElementById("toggleButton1").onclick = function (e) {
        if (error_occured)
            obj.Set('background.color', '#B6B6B4');
        else
            obj.Set('background.color', 'black');
        RG.redraw();
        error_occured = !error_occured;
    }

It does not change the chart background

There is modified file from RGraph examples. It must be copied to \demo folder.

http://rghost.net/6qZm2jCBS

What interesting: the call of

obj.Set('background.color', 'gray');

inside of drawGraph - works fine(!) But outside does not work.

ZedZip
  • 5,794
  • 15
  • 66
  • 119
  • Try changing this: RG.redraw(); to this: RGraph.redraw(); If that fails check the JavaScript console for an error message. And post a link to an example page. – Richard Jan 28 '15 at 23:17
  • Thank you. I downloaded RGraph, then modified sample file (see the initial post) and do experiment. I simply added button and function (see above too). I tried RG.redraw() and RGraph.redraw(). It does not work. There are no error messages in console. What I do wrong? – ZedZip Jan 29 '15 at 05:43
  • No idea. You'll need to put the file online so that I can see it. – Richard Jan 29 '15 at 10:33
  • 1. Download RGraph here: http://www.rgraph.net/download and unzip it. 2. Download my file here: http://rghost.net/6qZm2jCBS 3. Copy my file to RGraph install folder \demo – ZedZip Jan 29 '15 at 10:45
  • Your rghost URL results in a network error – Richard Jan 29 '15 at 12:04
  • I checked it works. But try this http://www37.zippyshare.com/v/mA0vNJgu/file.html\ – ZedZip Jan 29 '15 at 13:50
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/69829/discussion-between-richard-and-oleg). – Richard Jan 29 '15 at 15:10

1 Answers1

0

You need to add:

RGraph.redraw();

After the Set() call.

Richard
  • 4,809
  • 3
  • 27
  • 46