2015-11-07 43 views
1

我在ajax调用中收到此消息:[[8,2],[13,1],[17,1],[18,1],[7,1]]并将它传递给jquery flot。Jquery在重复数字时弄错了图形

的问题是,该图已开始在[7,1]它应该开始[8,2]和结束对[7,1]但它不是和它引起的怪异的图形:

see attached pic

这里是我的脚本:

$.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); 
     } 
    } 

我该如何解决这个问题?

回答

1

图形是7上的“开始”,因为7是数据中最小的x值,x轴与自然数一样排序。

如果作为数字使用类别插件的x值不应该被处理(见本fiddle):

xaxis: { 
    mode: 'categories' 
}, 
+0

在绑定标签的功能,如何我通过x的到消息的价值?谢谢。 –

+0

这应该和以前一样工作。 – Raidri

+0

是的,但问题是,我注意到我有一个错误,它显示的位置,而不是分配给该位置的值。 –