问题
I am using Flot Charts and I have 2 vectors that represent the x and y variables that look like this:
var x = [1.778,1.767,2.308,2.41]
var y = [35.94,35.97,36.01,36.04]
The problem is that when I want to plot, the following syntaxis:
$(document).ready(function () {
$.plot($("#placeholder"), [d1]);
});
does only allow to plot the d1 variable!! Which has the following form:
var d1= [ [0,0], [1,4], [2,7], [3,3], [4,2] ];
That is fine if you have 3 or 4 points to plot, but when you have almost 50 to plot, you need something more automatized.
My question is: Is there any way of plotting 2 ARRAY VARIABLES in Flot or converting them to plot them using a function?
回答1:
You can create a two dimensional array from x,y arrays like this
var x = [1.778,1.767,2.308,2.41];
var y = [35.94,35.97,36.01,36.04],d1=[];
for(var i=0;i<x.length;i++)
d1.push([x[i],y[i]]);
来源:https://stackoverflow.com/questions/31035311/plot-with-2-array-inputs-x-y