dc.js 折线图聚合 Month/Year
dc.js LineChart Aggregated by Month/Year
我试图绘制一个折线图,我想按月汇总数据。我正在使用来自 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 日被绘制为不同的点。我想将它们全部合并到 July-2017 点中。我该如何实现?任何指针?
谢谢大家!
这是一个 fiddle:
https://jsfiddle.net/usingh2buffaloedu/8u0etnwd/
我在 dc.js 中遇到时间渲染问题,但在您的示例中,关键是获取维度中的月份值。
var dateDimension = facts.dimension(function (d) {return d3.time.month(d.newDate); });
查看更新后的 fiddle (https://jsfiddle.net/ury1k1bs/1/)
我觉得.round()图表方法只对刷图有用,对渲染没有用
有关更多信息,请参阅 dc.js 提供的时间间隔示例...
http://dc-js.github.io/dc.js/examples/switching-time-intervals.html
我试图绘制一个折线图,我想按月汇总数据。我正在使用来自 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 日被绘制为不同的点。我想将它们全部合并到 July-2017 点中。我该如何实现?任何指针? 谢谢大家!
这是一个 fiddle: https://jsfiddle.net/usingh2buffaloedu/8u0etnwd/
我在 dc.js 中遇到时间渲染问题,但在您的示例中,关键是获取维度中的月份值。
var dateDimension = facts.dimension(function (d) {return d3.time.month(d.newDate); });
查看更新后的 fiddle (https://jsfiddle.net/ury1k1bs/1/)
我觉得.round()图表方法只对刷图有用,对渲染没有用
有关更多信息,请参阅 dc.js 提供的时间间隔示例... http://dc-js.github.io/dc.js/examples/switching-time-intervals.html