rwjblue / pivot.js

Build Pivot Tables from CSV/JSON Data
http://rwjblue.github.com/pivot.js/
Other
783 stars 134 forks source link

Working example with JSON #1

Closed hsalama closed 12 years ago

hsalama commented 12 years ago

Thanks for the great work! I am trying to recreate the example you have but using json instead of csv. However, I cannot figure out where the json would go. In one part of the docs you mention passing it to pivot.init(),

pivot.init({json: json_string, fields: field_definitions});

but in the example it is using setupPivot(). If I were to follow the example, should I just replace

setupPivot({url:'./lib/csv/demo.csv', fields: fields, filters: .......................}) 

with

setupPivot({myJSONString, fields: fields, filters: .......}) ??

Thanks again!

rwjblue commented 12 years ago

OK, so Pivot.js itself handles receiving JSON data by passing the 'json' property to init(). As stated in the README:

pivot.init({json: json_string, fields: field_definitions});

Unfortunately, jquery_pivot.js expects that anything passed with a 'url' property be in CSV format. I just pushed a commit to fix that (f45a004 and 7b5270e).

So at this point you can pass either CSV or JSON files in the 'url' property and it should work.


$('#pivot-demo').pivot_display('setup', 
   {url:'./lib/csv/demo.csv', 
    fields: fields, 
    filters: {employer: 'Acme Corp'}, 
    rowLabels:["city"], 
    summaries:["billed_amount", "payment_amount"]
   }
)

Keep in mind that if you use JSON you have quite a bit of repetition in the data file to be downloaded, and this will impact the size requirements. In our app we started out using JSON as a data source and had to switch to CSV do to the file sizes (data source of 20,000 rows and 25 fields was around 18MB for JSON and only 8MB for CSV).

Please let me know if you have any issues.

hsalama commented 12 years ago

Thanks Robert! I've been wrestling with it for the past week and I have reverted back to CSV as you suggested. However, my dataset is pretty large ~15,000 rows. I am caching the data so the initial load is pretty fast now. However, when you chage the "Raw Label Fields" selection (to add or remove columns) it becomes really sluggish, especially in IE. I am trying to figure out where it spends most of its time so I can try to optimize it. Any suggestions? Thanks again!

devivenkat commented 12 years ago

Hi Robert im new to this pivot js , i tried your example using csv , but in json couldn't fetch the result, i tried your above solution by changing the jquery pivot js, can you please give me example of json which you tried , it will be really helpful to me pls