浮选绘图仪在右下

浮选绘图仪在右下

显示我的图形效果很好,但将鼠标悬停在点上仅在图形的top 30%和left 10%一侧,我做错了吗?

该代码由多个按钮和更新触发,我是否以错误的方式更新它?



function loadGraph(myArr, percent) {

    var graphData = [{
        color: '#00FF00',
        data: []
    }, {
        color: '#FF0000',
        data: []
    }, {
        color: '#FFFF00',
        data: []
    }];

    var avgPrices = [];

    for (var i = 0; i < 10; i++) {
        var date = new Date(myArr.items[myArr.items.length - (i + 1)].date).getTime();
        if (lines.min == true) {
            graphData[0].data[i] = [date, myArr.items[myArr.items.length - (i + 1)].lowPrice]
        };
        if (lines.max == true) {
            graphData[1].data[i] = [date, myArr.items[myArr.items.length - (i + 1)].highPrice]
        };
        if (lines.avg == true || percent) {
            graphData[2].data[i] = [date, myArr.items[myArr.items.length - (i + 1)].avgPrice]
        };
        avgPrices.push(myArr.items[myArr.items.length - (i + 1)].avgPrice);
    }

    var plotBox = $('#graph-lines');

    var plot = $.plot(plotBox, graphData, {
        series: {
            points: {
                show: true,
                radius: 5
            },
            lines: {
                show: true
            },
            shadowSize: 0
        },
        grid: {
            color: '#00cece',
            borderColor: 'transparent',
            borderWidth: 0,
            hoverable: true
        },
        xaxis: {
            mode: "time"
        },
        yaxis: {
            tickFormatter: function(val, axis) {
                if (percent) {
                    return (val * 100).toFixed(1) + '%'
                } else {
                    return val.toFixed(2)
                }
            },
        }
    });

    var previousPoint = null;
    plotBox.bind('plothover', function(event, pos, item) {
        console.log('hovering!');
        if (item) {
            if (previousPoint !== item.dataIndex) {
                previousPoint = item.dataIndex;
                $('#tooltip').remove();
                var monthNames = ["January", "February", "March", "April", "May", "June",
                    "July", "August", "September", "October", "November", "December"
                ];

                var date = new Date(item.datapoint[0]);
                var x = monthNames[date.getMonth()] + " " + date.getDate() + " - " + date.getFullYear(),
                    y = item.datapoint[1];
                showTooltip(item.pageX, item.pageY, y + ' Interstellar Kredit (ISK) at ' + x);
            }
        } else {
            $('#tooltip').remove();
            previousPoint = null;
        }
    });

};

最佳答案

在获取显示工具提示的代码之前,您是否已检查调试器以查看是否收到错误?我看不到浏览器如何通过for循环;在我看来,您应该使索引超出范围错误。

对于所有三个if语句,尝试按以下方式更改if语句。

if (lines.avg == true || percent) {
            graphData[2].data.push([date, myArr.items[myArr.items.length - (i + 1)].avgPrice]);
        }


在上面的代码中,我将分号移到了then块内。另外,我将点推到数组上而不是访问索引(在您尝试访问它的位置数组看起来是空的)。

关于javascript - 浮选绘图仪在右下 Angular 不起作用,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/30106371/

10-11 21:51