Javascript 从D3.js中的时间序列折线图中筛选出周末

Javascript 从D3.js中的时间序列折线图中筛选出周末,javascript,date,d3.js,filtering,weekend,Javascript,Date,D3.js,Filtering,Weekend,我有一个多年的每日数据集,如下所示: date close 2013-09-17 178 2013-09-16 185 2013-09-15 20 2013-09-14 10 2013-09-13 190 2013-09-12 157 2013-09-11 150 2013-09-10 189 2013-09-09 183 2013-09

我有一个多年的每日数据集,如下所示:

date            close  
2013-09-17      178  
2013-09-16      185   
2013-09-15      20   
2013-09-14      10  
2013-09-13      190   
2013-09-12      157  
2013-09-11      150  
2013-09-10      189   
2013-09-09      183  
2013-09-08      11  
2013-09-07      20
我使用此方法生成了一个折线图,但希望过滤掉周末:

   <!DOCTYPE html>
<meta charset="utf-8">
<style>

body {
  font: 10px sans-serif;
}

.axis path,
.axis line {
  fill: none;
  stroke: #000;
  shape-rendering: crispEdges;
}

.x.axis path {
  display: none;
}

.line {
  fill: none;
  stroke: steelblue;
  stroke-width: 1.5px;
}

</style>
<body>
<script src="http://d3js.org/d3.v3.js"></script>
<script>

var margin = {top: 20, right: 20, bottom: 30, left: 50},
    width = 960 - margin.left - margin.right,
    height = 500 - margin.top - margin.bottom;

var parseDate = d3.time.format("%Y-%m-%d").parse;

var x = d3.time.scale()
    .range([0, width]);

var y = d3.scale.linear()
    .range([height, 0]);

var xAxis = d3.svg.axis()
    .scale(x)
    .orient("bottom");

var yAxis = d3.svg.axis()
    .scale(y)
    .orient("left");

var line = d3.svg.line()
    .x(function(d) { return x(d.date); })
    .y(function(d) { return y(d.close); });

var svg = d3.select("body").append("svg")
    .attr("width", width + margin.left + margin.right)
    .attr("height", height + margin.top + margin.bottom)
  .append("g")
    .attr("transform", "translate(" + margin.left + "," + margin.top + ")");

d3.csv("data.csv", function(error, data) {
  data.forEach(function(d) {
    d.date = parseDate(d.date);
    d.close = +d.close;
  });

  x.domain(d3.extent(data, function(d) { return d.date; }));
  y.domain(d3.extent(data, function(d) { return d.close; }));

  svg.append("g")
      .attr("class", "x axis")
      .attr("transform", "translate(0," + height + ")")
      .call(xAxis);

  svg.append("g")
      .attr("class", "y axis")
      .call(yAxis)
    .append("text")
      .attr("transform", "rotate(-90)")
      .attr("y", 6)
      .attr("dy", ".71em")
      .style("text-anchor", "end")
      .text("Price ($)");

  svg.append("path")
      .datum(data)
      .attr("class", "line")
      .attr("d", line);
});

</script>

from Crossfilter.js似乎可以实现周末过滤,但只针对数据集的一小部分。理想情况下,我可以使用复选框(例如,仅在整个数据集中的工作日或星期一)按天进行筛选。

我不确定是否可以使用d3.time.scale执行所需操作,因为它是线性比例,线性比例通常希望其域/范围是连续的。我想这取决于你是想把特定的日子归零,还是想在轴上跳过这些日子。前者是可能的,后者我不这么认为。另外,我看不出交叉过滤器示例是如何过滤周末的。底部的完整时间线显示了一周中的所有日子。另外,为了好玩,这里有一把小提琴演示了你的问题:你可以先从数据中筛选周末,然后绘制图表。如果你不想在你的图表中出现空白,那么你可以用序数来代替时间。这是我们为周末有缺口的财务数据所做的。您解决了这个问题吗?可能重复