简体   繁体   English

未捕获的TypeError:无法读取未定义的Morris.js的属性'x'

[英]Uncaught TypeError: Cannot read property 'x' of undefined Morris.js

I'm going nuts and I can't figure out what is causing this error. 我疯了,我不知道是什么导致了这个错误。

My Javascript: 我的Javascript:

<script>
$(document).ready(function() {


        var jqxhr = $.getJSON("rest/scriptruns/VeloxMorgana", function() {
            //VeloxMorgana.setData('[{"period":"2014-07-15","VeloxMorgana":1},{"period":"2014-07-16","VeloxMorgana":47}]');
        });

        jqxhr.complete(function() {
            if ($('#VeloxMorgana').length) {
                var week_data = jqxhr;
                var VeloxMorgana = Morris.Line({
                    element : 'VeloxMorgana',
                    data : week_data,
                    xkey : 'period',
                    ykeys : ['VeloxMorgana'],
                    labels : ['VeloxMorgana'],
                    events : ['2014-07-10', '2014-07-17']
                });
            }
        });

    });
</script>

My HTML 我的HTML

<!-- Widget ID (each widget will need unique ID)-->
        <div class="jarviswidget" id="wid-id-7" data-widget-editbutton="false">
            <!-- widget options:
            usage: <div class="jarviswidget" id="wid-id-0" data-widget-editbutton="false">

            data-widget-colorbutton="false"
            data-widget-editbutton="false"
            data-widget-togglebutton="false"
            data-widget-deletebutton="false"
            data-widget-fullscreenbutton="false"
            data-widget-custombutton="false"
            data-widget-collapsed="true"
            data-widget-sortable="false"

            -->
            <header>
                <span class="widget-icon"> <i class="fa fa-bar-chart-o"></i> </span>
                <h2>Time Graph</h2>

            </header>

            <!-- widget div-->
            <div>

                <!-- widget edit box -->
                <div class="jarviswidget-editbox">
                    <!-- This area used as dropdown edit box -->

                </div>
                <!-- end widget edit box -->

                <!-- widget content -->
                <div class="widget-body no-padding">

                    <div id="VeloxMorgana" class="chart no-padding"></div>

                </div>
                <!-- end widget content -->

            </div>
            <!-- end widget div -->

        </div>
        <!-- end widget -->

It loaded when I statically set the data, but when I use JSON it just freaks. 当我静态设置数据时,它就会加载,但是当我使用JSON时,它就怪胎了。

Here is the JSON it loads in when I call it using the ajax json feature and the load data (i've tried just putting it straight into the data from finishing the json request, same result). 这是当我使用ajax json功能调用它并加载数据时加载的JSON(我已经尝试过将JSON请求完成后直接放入数据中,结果相同)。

[  
   {  
      "period":"2014-07-15",
      "VeloxMorgana":1
   },
   {  
      "period":"2014-07-16",
      "VeloxMorgana":47
   }
]

The jqxhr is just the promise object for your XHR request, it doesn't actually contain the data that was received. jqxhr只是XHR请求的jqxhr对象,它实际上不包含接收到的数据。

Since you don't really deal with failure at all, I could recommend just using the success callback straight away: 由于您根本不真正处理失败,因此我建议您立即使用成功回调:

$.getJSON("rest/scriptruns/VeloxMorgana", function(data) {
    if ($('#VeloxMorgana').length) {
        Morris.Line({
            element : 'VeloxMorgana',
            data : data,
            xkey : 'period',
            ykeys : ['VeloxMorgana'],
            labels : ['VeloxMorgana'],
            events : ['2014-07-10', '2014-07-17']
        });
    }
});

Also, the documentation states: 此外, 文档指出:

The jqXHR.success() , jqXHR.error() , and jqXHR.complete() callback methods introduced in jQuery 1.5 are deprecated as of jQuery 1.8. jQuery 1.5中不推荐使用jqXHR.success()jqXHR.error()jqXHR.complete()回调方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Morris.js未捕获TypeError:无法读取未定义的属性“匹配” - Morris.js Uncaught TypeError: Cannot read property 'match' of undefined morris.js setData导致“未捕获的TypeError:无法读取未定义的属性&#39;x&#39;” - morris.js setData causes “Uncaught TypeError: Cannot read property 'x' of undefined” Morris.js:无法读取未定义的属性“ x” - Morris.js: Cannot read property 'x' of undefined Morris.js数据(无法读取未定义的属性“ match”) - Morris.js data (Cannot read property 'match' of undefined) 未捕获的TypeError:无法读取未定义的common.js的属性&#39;x&#39; - Uncaught TypeError: Cannot read property 'x' of undefined common.js js -Uncaught TypeError: Cannot read property 'x' of undefined at object (ball - js -Uncaught TypeError: Cannot read property 'x' of undefined at object (ball 未捕获的TypeError:无法读取未定义的属性“ x” - Uncaught TypeError: Cannot read property 'x' of undefined 未捕获的TypeError:无法读取未定义的属性x - Uncaught TypeError: Cannot read property x of undefined Chaplin.js-未捕获的TypeError:无法读取未定义的属性“未定义” - Chaplin.js - Uncaught TypeError: Cannot read property 'undefined' of undefined Javascript中的数组错误:未捕获的TypeError:无法读取未定义的属性&#39;x&#39; - Array Error in Javascript: Uncaught TypeError: Cannot read property 'x' of undefined
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM