1

I was hoping someone could help me get my head around an issue I'm having.

I'm working with Flot graphs and ruby on rails I have no issues setting up either of the two but I do have an issue with graphing multiple datasets on a single graph.

I'm querying a database and get the results back in an array like this

   [2015-2-01 12:00:00,50.4, 26.8,29.9,30.4] 
    [2015-2-01 12:10:00,56.4, 26.3,29.9,70.4]

after I get the results in ruby I'm creating an array of arrays for each result to put the title of the column along side it so I get something like this

[[TIME:2015-2-01 12:00:00] [CPU:50][IO:40]]
[[TIME:2015-2-01 12:15:00] [CPU:99][IO:40]] etc... 

My question is once I return this to my view in Rails I want to plot each series within Flot. (time with cpu , time with io , time with the other points)

flot expects it's data series to be like [[time,value],[time,value]]. So I need to figure out how to loop through my multi dimensional array and create separate arrays each containing the time and the value of the specific metric. Any insight is greatly appreciated. Also, I understand that the time value expected by flot is different than what I have specified.

thanks for the response. I can work on putting it in fiddle when I get home. Time is not the issue I know how to convert my time stamp to what flot is expecting. here is an example of the multi-dimensional array I'm receiving from my POST request  array[
array[
      0: "BTIME, 2015-02-27 18:00"
      1: "CPU, 50.0"
      2: "IOWAIT, 38.0"
      3: "CLWAIT, 0.0"
      4: "APWAIT, 0.0"
      5: "CCWAIT, 0.0"
      6: "PLSEXEC, 1.0"
      7: "JAVEXEC, 0.0]
array[
0: "BTIME, 2015-02-27 18:10"
1: "CPU, 44.0"
2: "IOWAIT, 35.0"
3: "CLWAIT, 0.0"
4: "APWAIT, 1.0"
5: "CCWAIT, 0.0"
6: "PLSEXEC, 1.0"
7: "JAVEXEC, 0.0"]

]

joe_dirte
  • 21
  • 2
  • Could you set up a [fiddle](http://jsfiddle.net/) or [plunkr](http://plnkr.co/) that is a close as possible to your current state? To use time you need to use `jquery.flot.time.js`. You can find more information about that [here](https://github.com/flot/flot/blob/master/API.md#time-series-data). – Michel de Nijs Mar 05 '15 at 09:49
  • thanks for the response. I can work on putting it in fiddle when I get home. Time is not the issue I know how to convert my time stamp to what flot is expecting. here is an example of the multi-dimensional array I'm receiving from my POST request – joe_dirte Mar 06 '15 at 22:54
  • Your multidimensional array has invalid syntax. Did you intend for that to be a Ruby or Javascript array? can you fix it? – Mark Thomas Mar 07 '15 at 00:43
  • I have similar problem - in my CSV file, each line contains timeStamp and some values that I want to display as separated flot charts. Is there a simple solution? or that I must duplicate my timeStamp for each csv.column ? – Atara Mar 03 '16 at 09:16

0 Answers0