Now works properly with multiple graphs on the same page.