簡體   English   中英

重復編號時jQuery Flot錯誤圖

[英]Jquery Flot wrong graph when repeating number

我收到此消息:ajax調用中的[[8,2],[13,1],[17,1],[18,1],[7,1]]並將其傳遞給jquery flot。

問題在於該圖從[7,1]開始,應該從[8,2]開始,到[7,1]結束,但是沒有,從而導致一個奇怪的圖:

見附件圖片

這是我的腳本:

$.ajax({
        url: "{{ URL::to('/ajaxcall') }}",
        method: 'GET',
        dataType: 'json',
        success: onOutboundReceived
    });

    function onOutboundReceived(series) {
        var series = series;
        //$.plot($('#site_tay'), finalData, options);
        var plot_statistics = $.plot($("#site_tay"), [{
            data: series,
            label: "Cotizaciones"
        }
        ], {
            series: {
                lines: {
                    show: true,
                    lineWidth: 2,
                    fill: true,
                    fillColor: {
                        colors: [{
                            opacity: 0.2
                        }, {
                            opacity: 0.01
                        }
                        ]
                    }
                },
                points: {
                    show: true
                },
                shadowSize: 2
            },
            legend:{
                show: false
            },
            grid: {
                labelMargin: 10,
                axisMargin: 500,
                hoverable: true,
                clickable: true,
                tickColor: "rgba(255,255,255,0.22)",
                borderWidth: 0
            },
            colors: ["#FFFFFF", "#4A8CF7", "#52e136"],
            xaxis: {
                ticks: 11,
                tickDecimals: 0
            },
            yaxis: {
                ticks: 5,
                tickDecimals: 0
            }
        });
        $("#site_tay").bind("plothover", function (event, pos, item) {

            var str = "(" + pos.x.toFixed(2) + ", " + pos.y.toFixed(2) + ")";

            if (item) {
                if (previousPoint != item.dataIndex) {
                    previousPoint = item.dataIndex;
                    $("#tooltip").remove();
                    var x = item.datapoint[0],
                            y = item.datapoint[1];
                    showTooltip(item.pageX, item.pageY,
                            item.series.label + " del dia " + x + " = " + y);
                }
            } else {
                $("#tooltip").remove();
                previousPoint = null;
            }
        });
        function showTooltip(x, y, contents) {
            $("<div id='tooltip'>" + contents + "</div>").css({
                position: "absolute",
                display: "none",
                top: y + 5,
                left: x + 5,
                border: "1px solid #000",
                padding: "5px",
                'color':'#fff',
                'border-radius':'2px',
                'font-size':'11px',
                "background-color": "#000",
                opacity: 0.80
            }).appendTo("body").fadeIn(200);
        }
    }

我怎樣才能解決這個問題?

該圖從7開始“開始”,因為7是數據中最小的x值,並且x軸的排序類似於自然數。

如果您的x值不應被視為數字,請使用Categories插件(請參閱此小提琴 ):

xaxis: {
    mode: 'categories'
},

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM