【问题标题】:dc.js LineChart Aggregated by Month/Yeardc.js LineChart 按月/年聚合
【发布时间】:2017-11-14 20:25:55
【问题描述】:

我试图绘制一个折线图,我想按月聚合数据。我正在使用来自crossfilter documentation 的数据集,日期稍作修改。

这就是我的数据集的样子:

var data = [
  {date: "2011-11-14T16:17:54Z", quantity: 2, total: 190, tip: 100, type: "tab"},
  {date: "2011-07-10T16:28:54Z", quantity: 1, total: 300, tip: 200, type: "visa"},
  {date: "2011-07-15T16:28:54Z", quantity: 1, total: 300, tip: 200, type: "visa"},
  {date: "2011-06-14T16:30:43Z", quantity: 2, total: 90, tip: 0, type: "tab"},
  {date: "2011-06-14T16:48:46Z", quantity: 2, total: 90, tip: 0, type: "tab"},
  {date: "2011-05-14T16:53:41Z", quantity: 2, total: 90, tip: 0, type: "tab"},
  {date: "2011-07-17T16:14:06Z", quantity: 1, total: 100, tip: 0, type: "cash"},
  {date: "2011-05-14T16:58:03Z", quantity: 2, total: 90, tip: 0, type: "tab"},
  {date: "2011-12-14T17:07:21Z", quantity: 2, total: 90, tip: 0, type: "tab"},
  {date: "2011-11-14T17:22:59Z", quantity: 2, total: 90, tip: 0, type: "tab"},
  {date: "2011-11-14T17:25:45Z", quantity: 2, total: 200, tip: 0, type: "cash"},
  {date: "2011-11-14T17:29:52Z", quantity: 1, total: 200, tip: 100, type: "visa"}
];

我想按月-年对总计进行分组。我的数据组根据日期而不是月份返回总计。

在我的图表中,7 月 10 日、15 日和 17 日被绘制为不同的点。我想将它们全部合并为 2017 年 7 月的积分。我如何做到这一点?任何指针? 谢谢大家!

这是一个小提琴: https://jsfiddle.net/usingh2buffaloedu/8u0etnwd/

【问题讨论】:

    标签: javascript d3.js dc.js crossfilter


    【解决方案1】:

    我在 dc.js 中遇到时间渲染问题,但在您的示例中,关键是获取维度中的月份值。

    var dateDimension = facts.dimension(function (d) {return d3.time.month(d.newDate); });
    

    查看更新的小提琴 (https://jsfiddle.net/ury1k1bs/1/)

    我觉得.round()图表方法只对刷图有用,对渲染没用。

    更多信息请参见 dc.js 提供的时间间隔示例... http://dc-js.github.io/dc.js/examples/switching-time-intervals.html

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2022-01-14
      • 2021-12-30
      • 2021-04-29
      • 2018-02-17
      • 2019-09-21
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多