如何修复 JavaScript 代码中的“Uncaught TypeError: Cannot read property 'range' of undefined”?

时间:2021-07-07 09:01:43

标签: vis.js

这里是 Javascript 的新手。 我目前正在尝试绘制从 vis.js 中的 Json 文件读取的 x、y 和 z 坐标中的数据。 代码如下。

<!doctype html>
<html>
<head>
  <title>Graph 3D | Animation</title>

  <style type="text/css">
    body {
      font: 10pt arial;
    }
  </style>

  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
  <script type="text/javascript" src="./standalone/umd/vis-graph3d.js"></script>
  <script type="text/javascript">
    var data = null;
    var graph = null;

    // Called when the Visualization API is loaded.
    function drawVisualization() {
      console.log('drawVisualization >>')
      coor = new vis.DataSet();
      $(document).ready(function(){
        $.getJSON('./server/Output/202176112622.json', function(data){
            $.each(data,function(i,item){
                var x, y, z;
                coor.add([
                  {x:item.x, y:item.y, z:item.z}
                ]);
            });
        });
      });
      
      // specify options
      var options = {
        width:  '800px',
        height: '600px',
        style: 'surface',
        showPerspective: true,
        showGrid: true,
        showShadow: false,
        // showAnimationControls: false,
        keepAspectRatio: true,
        verticalRatio: 0.5,
        animationInterval: 100, // milliseconds
        animationPreload: true
      };
      // create our graph
      var container = document.getElementById('mygraph');
      graph = new vis.Graph3d(container, coor, options);
    };    
  </script>
  
</head>

<body onload="drawVisualization();">
<div id="mygraph"></div>

<div id="info"></div>
<p>Hello sanion</p>
</body>
</html>

但是,由于出现错误,我似乎无法绘制图形。

Uncaught TypeError: Cannot read property 'range' of undefined
    at Graph3d._setScale (Graph3d.js:197)
    at Graph3d._initializeRanges (Graph3d.js:365)
    at Graph3d._readData (Graph3d.js:636)
    at Graph3d.setData (Graph3d.js:648)
    at new Graph3d (Graph3d.js:186)
    at drawVisualization (04_animation.html:49)
    at onload (04_animation.html:55)

这是我收到错误的部分行。

Graph3d.prototype._setScale = function() {
  this.scale = new Point3d(
    1 / this.xRange.range(),
    1 / this.yRange.range(),
    1 / this.zRange.range()
  );

我需要在代码中以某种方式定义 range 的参数吗?

0 个答案:

没有答案