简体   繁体   English

如何在d3js / dimplejs图表中过滤系列?

[英]How to filter series in d3js/dimplejs charts?

I want to make d3js/dimplejs chart to a responsive/interactive one. 我想使d3js / dimplejs图表成为响应式/交互式的。 I want to filter the 'series' according to the clicks in 'legends'. 我想根据“传奇”中的点击过滤“系列”。 I tried like below. 我尝试如下。 But This is not hiding the 'series' as I expected. 但这并没有像我预期的那样隐藏“系列”。 This works pretty charm with 'bubble' chart. 这对“气泡”图很有用。

    var svg = dimple.newSvg("#chartContainer", 700, 450);
    data = [
   {
    "Standby Date":"01-DEC-2013 00:00:00",
    "Value type":"Actual",
    "Value":118,
            "Code":"code1"
  },
  {
    "Standby Date":"01-DEC-2013 00:00:00",
    "Value type":"Planned",
    "Value":74,
            "Code":"code1"
  },
  {
    "Standby Date":"02-DEC-2013 00:00:00",
    "Value type":"Actual",
    "Value":128,
            "Code":"code2"
  },
  {
    "Standby Date":"02-DEC-2013 00:00:00",
    "Value type":"Planned",
    "Value":157,
            "Code":"code2"
  },
  {
    "Standby Date":"03-DEC-2013 00:00:00",
    "Value type":"Actual",
    "Value":142,
            "Code":"code3"
  },
  {
    "Standby Date":"03-DEC-2013 00:00:00",
    "Value type":"Planned",
    "Value":154,
            "Code":"code3"
  }
];
    var myChart = new dimple.chart(svg, data);
    myChart.setBounds(70, 40, 490, 320)   
    var x = myChart.addTimeAxis("x", "Standby Date", "%d-%b-%Y %H:%M:%S", "%d-%b");
            var y = myChart.addMeasureAxis("y","Value");
    var s = myChart.addSeries("Value type", dimple.plot.area);
    s.lineMarkers = true;
    var myLegend = myChart.addLegend(180, 10, 360, 20, "right");
    myChart.draw();       
            myChart.legends = [];
            var filterValues = dimple.getUniqueValues(data, "Value type");
        myLegend.shapes.selectAll("rect")
          .on("click", function (e) {
            var hide = false;
            var newFilters = [];
            filterValues.forEach(function (f) {
              if (f === e.aggField.slice(-1)[0]) {
                hide = true;
              } else {
                newFilters.push(f);
              }
            });
            if (hide) {
              d3.select(this).style("opacity", 0.2);
            } else {
              newFilters.push(e.aggField.slice(-1)[0]);
              d3.select(this).style("opacity", 0.8);
            }
            filterValues = newFilters;
            myChart.data = dimple.filterData(data, "Value type", filterValues);
            myChart.draw(800);
           });

I also want to filter the charts with 'Code' as well. 我也想用“代码”过滤图表。 Is it possible to get it through by Legend? 传奇有可能通过它吗? Or any other possible ways? 或任何其他可能的方式?

I have not used dimple.js but have been very impressed with dc.js, http://dc-js.github.io/dc.js/ . 我没有使用过dimple.js,但是对dc.js http://dc-js.github.io/dc.js/印象深刻。 Like dimple, dc.js is a library that provides convenient methods for making charts with d3.js. 与dimple一样,dc.js是一个库,提供了使用d3.js制作图表的便捷方法。 More important is that dc.js is designed to provide reactive charts that dynamically update as user interaction filters the underlying data set. 更重要的是,dc.js旨在提供响应式图表,该图表可在用户交互过滤基础数据集时动态更新。 dc.js builds interactive charts on top of a Crossfilter, http://square.github.io/crossfilter/ http://blog.rusty.io/2012/09/17/crossfilter-tutorial/ . dc.js在Crossfilter( http://square.github.io/crossfilter/ http://blog.rusty.io/2012/09/17/crossfilter-tutorial/)的顶部构建交互式图表。 Crossfitler provides the functionality to programmatically sort, filter, aggregate rows of data on the client. Crossfitler提供了以编程方式对客户端上的数据行进行排序,过滤和聚合的功能。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM