CustomJS to create a csv

Here is another thread with a solution: Save plot data as csv