2014-07-24 132 views
0

在一個正常運作的JS結束時,我有三個陣列X - 和Ÿ座標 - ,return [theta_plot, omega_plot, e_plot];,我想發送到海軍報密謀:傳遞陣列海軍報

function myPlot(theta_plot, omega_plot, e_plot) { 
    "use strict"; 
    function doPlot(position) { 
    $.plot("#placeholder", [ 
     { 
     data: theta_plot, 
     label: "Angle (rad)", 
     yaxis: 1, 
     color: "red" 
     }, 
     { 
     data: omega_plot, 
     label: "Angular Velocity (rad/sec)", 
     yaxis: 2, 
     color: "green" 
     }, 
     { 
     data: e_plot, 
     label: "Energy (J)", 
     yaxis: 3, 
     color: "blue" 
     } 
    ], 
     { 
     yaxes: [ 
      { 
      font: { color: "red" } 
      }, 
      { 
      font: { color: "green" } 
      }, 
      { 
      font: { color: "blue" } 
      }, 
      { alignTicksWithAxis: position === "left" ? 1 : null } 
     ], 
     legend: { position: "nw" } 
     } 
    ); 
    } 
    doPlot("left"); 
} 

外部function是我最近嘗試將這些陣列傳遞給Flot,但沒有成功。內部的function顯然是Flot。在我的JS中放置doPlot會產生所需的結果,儘管JSLint抱怨說它們沒有被定義,因爲它應該。但是,爲了組織的目的,我想在我的HTML中使用doPlot。問題:我如何讓doPlot知道我的陣列?

回答

2

只是

function doPlot(theta_plot, omega_plot, e_plot, position) { 

更換

function doPlot(position) { 

,並直接調用新的功能,而無需使用myPlot()功能。