是否有任何文档可用于构建类似于我们在 Stack Overflow profile/reputation 中找到的 Flot 图?标签?
从源代码中我可以看到在这个地址查询数据:/users/rep-graph/341106/"+ ranges.xaxis.from.toFixed(1) + "/"+ ranges.xaxis .to.toFixed(1)
但我不知道 from
和 to
字段 URL 中的值可以接受。
编辑:
在这张图中,我们可以看到突出显示了两个点,结果是在旁边列出了两个问题,这意味着绘制的值与user-定义的数据。
但是,如果我考虑 pkh 的例子,只有点(和标签)被提供给 Flot:
label: "United States",
data: [[1990, 18.9], [1991, 18.7] ....
所以我想看看:
- 如何将数据与点关联起来
- 如何根据图形选择更新面板[但这部分可能实际上不是由 Flot 自己完成的]
最佳答案
在这种情况下,他们通过 URL 传回 Javascript 时间戳。
所以在后端,他们必须做这样的事情(伪代码):
//get parameters from URL, non-rails people would just use POST or GET variables
$from = $_GET['from']
$to = $_GET['to']
//convert to timestamps in your language
$from = $from/1000
$to = $to/1000
//query your data source with these time-based restrictions
//return a JSON data set with the given restrictions, linking the known timestamps to labels
对于您的第二个问题,让您的服务器端返回一个关联数组,将时间戳链接到一个数据对象,在本例中包含 Gain、Loss、Url、Title。在成功回调中,您显示它们。这是一个示例数据对象:
{ 1274774400000 : {
Gain:0,
Loss:10,
Url:'http://asdf.com',
Title:'We lost some rep here... boohoo'
},
1274947200000 : {
Gain:10,
Loss:0,
Url:'http://asdf.com',
Title:'We gained some rep here... woo!'
}
}
您可以在您引用的页面的 showReputation
函数中看到这种类型的对象...只是它们返回的是 JSON 数组而不是对象。
给定上述数据对象,您可以轻松添加的另一个功能:一个 plotclick 事件,在单击它时突出显示给定的数据点。
关于javascript - Stack Overflow 信誉图 (Flot) 的文档,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3556561/