Plotting multiple datasets in Flot from a multidim

2019-08-06 12:03发布

问题:

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"]

]