views:

20

answers:

2

I know Im missing something retarded here... All Im trying to do is graph f(x) = 2500 for a range of x from -75 to 75. This should make a horizontal line. Right now, I think its a misunderstanding on my part of some specifics of arrays. It starts at 0 and goes to 75 fine, it does not graph lower than 0. (I get half the line)

for(x = -75; x<75; x++)
{
    a_const[x] = [x, 2250];
}

Im about certain the problem is there. Heres my .plot function, just to be sure.

$.plot(
        $("#mydiv"), 
        [
            //{label : "f(x) = x^2", data : a_exp},
            //{label : "f(x) = sqrt(x)", data : a_sqroot},
            //{label : "f(x) = 3root(x)", data : a_cuberoot}
            {label: "constant", data : a_const}

        ],
        {
            //yaxis: {min:-5000},
            xaxis: {min:-75},
            yaxis: {min:-1000},
            yaxis: {max:4000},
            grid: {hoverable:true, clickable:true },
            series: { points: {show:true}, lines:{show:true}}

        }
    );
+1  A: 

You can't have negative array subscripts. Just do

for (x = -75, x < 75; x++ )
{
      a_const.push( [x,2250] );
}

This will end up with elements with indices from 0 to 149, but containing pairs from [-75,2250] to [75,2250].

tvanfosson
A: 

NM, figured it out. a[-75] a[-74] (etc...) is not seen by flot do to it being negative. Solution :

for(x = -75; x<75; x++)
{
    a_const[x+75] = [x, 2250];
}

Would be nice to find / quote the official rule on negative indices.

jason