[英]How to filter series in d3js/dimplejs charts?
我想使d3js / dimplejs图表成为响应式/交互式的。 我想根据“传奇”中的点击过滤“系列”。 我尝试如下。 但这并没有像我预期的那样隐藏“系列”。 这对“气泡”图很有用。
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);
});
我也想用“代码”过滤图表。 传奇有可能通过它吗? 或任何其他可能的方式?
我没有使用过dimple.js,但是对dc.js http://dc-js.github.io/dc.js/印象深刻。 与dimple一样,dc.js是一个库,提供了使用d3.js制作图表的便捷方法。 更重要的是,dc.js旨在提供响应式图表,该图表可在用户交互过滤基础数据集时动态更新。 dc.js在Crossfilter( http://square.github.io/crossfilter/ http://blog.rusty.io/2012/09/17/crossfilter-tutorial/)的顶部构建交互式图表。 Crossfitler提供了以编程方式对客户端上的数据行进行排序,过滤和聚合的功能。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.