javascript - 查找 d3 中多个数据维度的范围

标签 javascript d3.js

如何使用三个不同的数据维度计算出我的域的范围?考虑以下数据:

var data = [
  {
    "Date":"10-10-2013",
    "High1" : 3049,
    "High2" : 2100,
    "high3" : 43
  },
  {
    "Date":"09-10-2013",
     "High1" : 3142,
    "High2" : 2010,
    "high3" : 23
  },
  {
    "Date":"08-10-2013",
    "High1" : 3099,
    "High2" : 2190,
    "high3" : 90

  }

我想为 High1 绘制一条线,为 High2 绘制一条线,为 High3 绘制另一条线,因此需要找到所有组合的范围,以便我可以为我的图表创建 y 轴。

最佳答案

var extents = ["High1", "High2", "high3"].map(function(dimensionName) {
    return d3.extent(data, function(d) { return d[dimensionName] });
});

var extent = [d3.min(extents, function(d) { return d[0] }),
              d3.max(extents, function(d) { return d[1] })];

这首先单独计算每个维度的范围,然后选择全局最小值和最大值。

关于javascript - 查找 d3 中多个数据维度的范围,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19844314/

相关文章:

javascript - Vue 测试 - '... .push is not a function'

javascript - 页面刷新后,contentEditable 无法与 localStorage 一起使用

javascript - slim : $: 是什么意思?

javascript - D3js exit() 和更新工作,无法进入()

javascript - SimpleHTTPServer 代码 404,消息未找到文件

javascript - 使用 Angular-cli 的 D3 V4 多线图

javascript - 将 2 个数组参数传递给 wasm

java - org.openqa.selenium.UnhandledAlertException : unexpected alert open

javascript - 单击按钮或输入搜索字段时使用新数据重绘 D3 饼图

Javascript d3 : Is there a way to programmatically stop dragging an item?