javascriptprotovis

Protovis update data with Javascript


I have this script protovis :

<script type="text/javascript+protovis">
    var w = 600;
    var h = 600;
    var img = new pv.Panel()
        .width(w)
        .height(h);

    img.add(pv.Image)
        .url("./icon/image.gif")
        .title("image");

    img.add(pv.Dot)
        .data(data)
        .left(function(d) d[0] * w)
        .bottom(function(d) d[1] * h)
        .size(function(d) d[2] * 100)
        .fillStyle("rgba(30, 120, 180, .6)")
        .strokeStyle("white");

    img.render();
</script>

data1 is declared in a Javascript file :

var data = [[.1, .1, 1], [.2, .2, 2], [.3, .3, 3]];

When i test that i have my image with 3 dots. But i don't how to do if for example i change the data in a Javascript function then redraw the protovis with the new data. In my case, when the user click in a menu, i recieve new data from a database and i update the data. But after i changed the data i need to redraw the image.

I was wondering how i could reload the web page in order to redraw the image with the new data. I was thinking of reload the web page passing the data in POST and retrieve the data in Javascript before drawing the image.

But i'm not sure if this solution will work and if it's the best way to do that.


Solution

  • Your question is a bit unclear, but there are several ways to do this:

    But really, unless you're going to be changing other things on the page as well, you're probably better off going with the AJAX option. It's no more complex on the server side, only a tiny bit more complex on the client side, and it saves your user a page load.