0

Hi so I'm using Highcharts.js to create a line graph with multiple lines. The data of each line is currently in seperate columns of a spreadsheet.

I can output this spreadsheet as a CSV but it moves across the columns rather than down the rows. How would I convert this CSV which would give me groups of comma seperated values for each row?

For each line of the chart I need a series of data that looks like this...

data: [49.9, 71.5, 106.4, 129.2, 144.0, 176.0, 135.6, 148.5, 216.4, 194.1, 95.6, 54.4]

Everything is inside Javascript code so I presume I need to write something which will cycle through the CSV and..

1) See how many comma seperated values there are per line (This will be the number of columns)

2) If there is 4 columns just take the 1st, 5th, 9th, 13th value and put it in a comma-seperated array.

3) Do this for each column so I have 4 arrays I can use in the chart

I'm sure this is childsplay but I'm more of a frontend designer so this has stumped me.

Thanks for any advice

bboybeatle
  • 549
  • 1
  • 8
  • 28
  • Can we fiddle on this? Seems easy but need the static data. – harshes53 Dec 11 '14 at 13:34
  • Sorry I don't really know how to use fiddle. I made one but can't link the csv file ... http://jsfiddle.net/192xmbwb/2/ – bboybeatle Dec 11 '14 at 13:45
  • [refer this for adding csv into fiddle](http://stackoverflow.com/questions/22890836/loading-external-csv-file-in-jsfiddle) – harshes53 Dec 11 '14 at 15:29
  • Anyways, this [Highcharts API documentation](http://www.highcharts.com/docs/working-with-data/preprocessing-data-from-a-file-csv-xml-json) has everything you require. Refer: Step **2** and **3** under **PREPROCESS DATA USING CSV** – harshes53 Dec 11 '14 at 17:42
  • @hbk35 I tried that but I don't know how to parse that data to ajax, as that example you've posted is for d3. Like i said im a bit of a noob, I started with that documentation first and half went over my head so I came here. If you could try and fix my fiddle we can try and sort this out. Would be much appreciated, THANKS - http://jsfiddle.net/192xmbwb/6/ – bboybeatle Dec 16 '14 at 12:39
  • let me try.. Update the fiddle with your csv data. I'll get my hands on later.. – harshes53 Dec 16 '14 at 13:00
  • I updated the fiddle with the CSV data in a
     div but I don't know how to attach it. In my example I call in a  URL. I don't know how I'd do the same in here
    – bboybeatle Dec 17 '14 at 11:12
  • @hbk35 The real problem is (other than me being a newby) is using the way suggested on highcharts to get my data on a complex type of chart. Here I have it working on a basic one.. http://thetally.efinancialnews.com/tallyassets/oilrevenue/chart6.html but when I transfer that same method over to my own, I get lost... http://thetally.efinancialnews.com/tallyassets/oilrevenue/chart5.html – bboybeatle Dec 17 '14 at 12:28
  • hmm weird let me see.. – harshes53 Dec 17 '14 at 13:25
  • Hey I got slightly closer. The square brackets atound the xAxis were messing things up – bboybeatle Dec 17 '14 at 14:27
  • So I'm close but I realise the problem. In my original spreadsheet I want each column as a category, and the sequential values in that column as the values across the x axis. Now its doing the opposite, putting each row as a category. – bboybeatle Dec 17 '14 at 15:05
  • share me your fiddle link.. which fiddle you are working on it? – harshes53 Dec 17 '14 at 15:27
  • Thanks, but I still didnt figure out how to use the CSV data in a fiddle so I'm just doing it on my server. Here I have it inputting the data from the CSV http://thetally.efinancialnews.com/tallyassets/oilrevenue/chart7.html but this is what it should look like... here Ive just entered the data http://thetally.efinancialnews.com/tallyassets/oilrevenue/chart3.html – bboybeatle Dec 17 '14 at 15:31
  • HAHA! I did some work in fiddle yesterday. Sorry been busy so much.. – harshes53 Dec 17 '14 at 15:35
  • are you up and running? do you have any issues anymore? – harshes53 Dec 17 '14 at 15:39
  • Nope. my data is going on the wrong axis still and I don't know how to modify my statement parsing the data to get it right. Did you look at those 2 links previously? The first one ive parsed the data to, but its supposed to look like the second. If you have any ideas to correct that function would be greatly appreciated. Thanks a lot for your help so far – bboybeatle Dec 17 '14 at 15:49
  • can you ping me the exact `data` content in our $.ajax call... to my email: someone865@gmail.com Sorry could have emailed you but couldn't find yours.. – harshes53 Dec 17 '14 at 16:05
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/67137/discussion-between-hbk35-and-bboybeatle). – harshes53 Dec 17 '14 at 16:07
  • I guess this issue is fixed,right? – harshes53 Dec 18 '14 at 16:35

0 Answers0