javascript - How to put together an options object in flot -
i have following javascript:
if(i==1&&$('#ln').val()=='true') ops={ xaxis: {show:false}, yaxis: {show:false, transform: function (v) { return -v; }, inversetransform: function (v) { return -v; }}} else ops={xaxis: {show:false}, yaxis: {show:false}}; $.plot($(gr), pdat,ops); when tried make string of ops got errors on parsing it. suppose it's because of functions. how can put options can add other options according different conditions? in example idea avoid repeating xaxis: {show:false}, yaxis: {show:false}
you can populate ops object common properties , add others in if statement:
// initalize ops common properties var ops = { xaxis: {show: false}, yaxis: {show: false} }; if (i == 1 && $('#ln').val() == 'true') { ops.yaxis.transform = function (v) { return -v; }; ops.yaxis.inversetransform = function (v) { return -v; }; } $.plot($(gr), pdat, ops);
Comments
Post a Comment