Plotting points in 2 arrays using flot

35 views
Skip to first unread message

Skand Vishwanath Peri

unread,
May 30, 2016, 12:31:49 PM5/30/16
to Flot graphs
I have two arrays namely xFinal and yFinal each of length 100. I want to plot the points (x,y) where x belongs to xFinal and yFinal correspondingly i.e (x=xFinal[i],y=yFinal[i]). I want these points to be plotted using the JS plotting library FLOT. How can I do it?

Here is my code
<script type="text/javascript">
$(document).ready(function() {
//--------------------Generated Random data points that Lie on a circle ---------------------------------
var arr = [];
for (var i=0, t=100; i<t; i++) {
    arr.push(Math.round(Math.random() * t)+100)
}
//document.write(arr);
x = numeric.sin(arr); // sin values
y = numeric.cos(arr) // corresponding cos values


//-------------------------------------------------------------------------------------------------------
a = [[1,3],[5,6]];
M = [x, y];
M = numeric.transpose(M);
U = numeric.svd(a).U;
S = numeric.svd(a).S;
V = numeric.svd(a).V;
S = numeric.diag(S);
fin =  numeric.dot(M,a);
fin = numeric.transpose(fin);
var xFinal=[];
var yFinal=[];
for(var i=0;i<100;i++)
{
xFinal.push(fin[0][i]);
yFinal.push(fin[1][i]);
}
$.plot($("#flot-placeholder"),[xFinal,yFinal]);


});
</script>


Reply all
Reply to author
Forward
0 new messages