【问题标题】:Flot Graph Number of Data pointsFlot Graph 数据点数
【发布时间】:2012-01-10 06:41:24
【问题描述】:

我需要使用 x 轴选择绘制具有缩放功能的图形,我正在使用 Flot 绘制图形。我必须显示缩放后存在的点数。 我总是得到总长度而不是缩放长度。

请帮助

【问题讨论】:

  • 您的意思是“Plot”,如“Plot Graph Number of Data Points”?
  • flot 不会改变数据集,所以如果你想知道可见点你必须自己计算。

标签: javascript jquery flot


【解决方案1】:

在您的“plotzoom”回调中,您可以像这样(来自网站上的示例)获取最小和最大 x / y 坐标:

placeholder.bind('plotzoom', function (event, plot) {
    var axes = plot.getAxes();
    $(".message").html("Zooming to x: "  + axes.xaxis.min.toFixed(2)
                       + " – " + axes.xaxis.max.toFixed(2)
                       + " and y: " + axes.yaxis.min.toFixed(2)
                       + " – " + axes.yaxis.max.toFixed(2));
});

您可以使用这些来计算此矩形内有多少点。

我可以建议使用 underscore.js 过滤功能来简化吗?

例如。

var xmin = axes.xaxis.min.toFixed(2);
var xmax = axes.xaxis.max.toFixed(2);
var ymin = axes.yaxis.min.toFixed(2);
var ymax = axes.yaxis.max.toFixed(2);

var points = [{x: 1, y:20} ..some points.. {x: 30, y: -23}];

var shownpoints = _.filter(points, function(point){ 
    return point.x > xmin && 
           point.x < xmax && 
           point.y > ymin && 
           point.y < ymax;
    }
);

这将给出一个数组,其中包含 x 和 y 最大值之间的点。然后您可以使用长度来获取计数!

【讨论】:

  • 如何获取点数组?我将数据传递为 {"label": "Label 1","data": [[x,y],[x,y]......]
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2010-12-22
相关资源
最近更新 更多