简体   繁体   English

关于FLOT CHARTS API错误:无法读取未定义的属性“ length”

[英]regarding FLOT CHARTS API Error :Cannot read property 'length' of undefined

hi this is my code for the FLOT charts API. 嗨,这是我的FLOT Charts API代码。 I am getting the graph but I am getting the above mentioned error. 我正在获取图形,但是正在获取上述错误。 Here is my code: 这是我的代码:

JavaScript: JavaScript的:

$(function () {
    var a1 = [
        [0, 1],
        [1, 2],
        [2, 6],
        [3, 9],
        [4, 5]
    ];
    var a2 = [
        [0, 4],
        [1, 5],
        [2, 1],
        [3, 7],
        [4, 7]
    ];
    var data = [{
        label: "Pre Transformation",
        data: a1
    }, {
        label: "Post Transformation",
        data: a2
    }];

    $.plot($("#consolidate1"), data, {
        series: {
            bars: {
                show: true,
                barWidth: 0.13,
                order: 1,
                align: "center"
            }
        },
        xaxis: {
            ticks: [
                [0, "Overall"],
                [1, "SEA"],
                [2, "INDIA"],
                [3, "NEA"],
                [4, "PZ"]
            ],
            tickLength: 0
        },
        grid: {
            hoverable: true,
            clickable: true,
            labelMargin: 15
        },

        valueLabels: {
            show: false
        }
    });
});


var previousPoint = null,
    previousLabel = null;

function showTooltip(x, y, color, contents) {
    $('<div id="tooltip">' + contents + '</div>').css({
        position: 'absolute',
        display: 'none',
        top: y - 40,
        left: x - 120,
        border: '2px solid ' + color,
        padding: '3px',
            'font-size': '9px',
            'border-radius': '5px',
            'background-color': '#fff',
            'font-family': 'Verdana, Arial, Helvetica, Tahoma, sans-serif',
        opacity: 0.9
    }).appendTo("body").fadeIn(200);
}

$("#consolidate1").on("plothover", function (event, pos, item) {
    if (item) {
        if ((previousLabel != item.series.label) || (previousPoint != item.dataIndex)) {
            previousPoint = item.dataIndex;
            previousLabel = item.series.label;
            $("#tooltip").remove();

            var x = item.dataIndex;
            var y = item.datapoint[1];
            var color = item.series.color;

            //console.log(item.series.xaxis.ticks[x].label);               

            showTooltip(item.pageX,
            item.pageY,
            color,
                "<strong>" + item.series.label + "</strong><br>" + item.series.xaxis.ticks[x].label + ":  <strong>" + y + "</strong>");
        }
    } else {
        $("#tooltip").remove();
        previousPoint = null;
    }
});

HTML Code: HTML代码:

<div>
    <p>Yearly Energy Consumption</p>
    <div id="consolidate1" style="width:500px;height:300px;"></div>
</div>

Code in Fiddle . 小提琴中的代码。

I am not able to figure out why this error is coming up. 我无法弄清楚为什么会出现此错误。

I got the similar error ... on debugging i found that the error was pointing to "~/float.js" .... then later i checked my code, there was another chart that i was trying to plot and for that chart i commented out the Html part of the chart.. so i was getting the above mentioned error. 我收到了类似的错误...在调试时,我发现错误指向“〜/ float.js”...。然后,我检查了我的代码,有另一个图表正在尝试绘制,并且针对该图表我注释掉了图表的HTML部分。.所以我遇到了上述错误。

The way i fixed is : commented out the $.plot() for other chart. 我固定的方式是:注释掉$ .plot()其他图表。

Hope this might help someone! 希望这可以对某人有所帮助!

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

相关问题 浮动图表:无法读取未定义的属性“插件” - flot charts: Cannot read property 'plugins' of undefined 出现错误:无法读取未定义的属性“长度” - Getting Error regarding :Cannot read property 'length' of undefined 谷歌图表错误:无法读取未定义的属性“长度”; Google图表中的调试错误 - Google charts error:Cannot read property 'length' of undefined; Debugging error in Google Charts json api 和错误结果:无法读取未定义的属性“长度” - json api and result with error: Cannot read property 'length' of undefined 无法读取未定义错误的属性“长度” - Cannot read property 'length' of undefined error DataTable错误 - 无法读取未定义的属性“长度” - DataTable Error - Cannot read property 'length' of undefined 打字机错误:无法读取未定义的属性“长度” - Typer Error: Cannot read property 'length' of undefined 无法读取 JavaScript 上未定义错误的属性“长度” - Cannot read property 'length' of undefined ERROR on JavaScript 无法读取未定义错误的属性“长度”-ReactJS - Cannot read property 'length' of undefined Error - ReactJS 无法读取未定义的属性“长度” - JavaScript 中的错误 - Cannot read property 'length' of undefined - Error in JavaScript
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM