jquery flot缩放选择不适用于图表

时间:2015-12-17 06:25:57

标签: javascript jquery flot

我是jQuery flot的新手,我有两个图表我想连接两个用于缩放和选择功能,

代码:

      // now connect the two

  $("#time_chart").bind("plotselected", function(event, ranges) {

    // clamp the zooming to prevent eternal zoom

    if (ranges.xaxis.to - ranges.xaxis.from < 0.00001) {
      ranges.xaxis.to = ranges.xaxis.from + 0.00001;
    }

    if (ranges.yaxis.to - ranges.yaxis.from < 0.00001) {
      ranges.yaxis.to = ranges.yaxis.from + 0.00001;
    }

    // do the zooming

    plot = $.plot("#time_chart", time_series,
      $.extend(true, {}, options, {
        xaxis: {
          min: ranges.xaxis.from,
          max: ranges.xaxis.to
        },
        yaxis: {
          min: ranges.yaxis.from,
          max: ranges.yaxis.to
        }
      })
    );

    // don't fire event on the overview to prevent eternal loop

    time_overview.setSelection(ranges, true);
  });

  $("#time_overview").bind("plotselected", function(event, ranges) {
    plot.setSelection(ranges);
  });

请参阅演示:

http://jsfiddle.net/w47agnq2/

我的图表正确显示了数据,但我觉得连接这两个数据我犯了一些错误。

$.plot("#time_chart", time_series,
          $.extend(true, {}, options, {
传递time_series

请帮帮我。

1 个答案:

答案 0 :(得分:1)

经过一些修正后,请参阅updated fiddle

<强>的变化:

http://www.flotcharts.org/flot/jquery.flot.selection.js添加到外部资源。

$.plot($("#time_chart"), [time_series], time_options);
var plot = $.plot($("#time_chart"), [time_series], time_options);

plot = $.plot("#time_chart", time_series,
plot = $.plot("#time_chart", [time_series],

$.extend(true, {}, options, {
$.extend(true, {}, time_options, {