Search code examples
jquerycsvflot

Loading csv file into jQuery?


I have a CSV file that I would like to use as source data for a jQuery flot graph.

Should I:

  1. Find a jQuery plugin that will load the CSV file directly?
  2. Convert the CSV file into JSON and use that instead?
  3. Do something completely different?

I'm not having much luck finding a jQuery plugin that can cope with an external CSV file, but maybe I'm missing something.


Solution

  • Use the jQuery CSV plugin to get an array. Build / sort the array however you need for the chart.

    jQuery CSV Plugin

    It just occured to me you may be thinking of reading a flat CSV file with jQuery. That's not possible. Giving javascript access to the filesystem sounds like a terrible idea. You can always use $.get() to load a file on a server, though.