Is there any reason that you have to use JS to redo the array? I did something like this once and had the buttons monitored by JS, then when you click it set a hidden var (with a name like sort) and submitted the page. Then my PHP read in everything and redrew the graph based on what we were sorting by. It wasn't as difficult as it sounds - the only problem was they decided that it wasn't pertinent to that graph, so we aren't using it anymore. I don't know if I have any of the code left.