Plot with 2 array inputs x-y

拟墨画扇 提交于 2019-12-12 05:10:07

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!