简体   繁体   English

D3 Focus + Context通过笔刷不显示散点图

[英]D3 Focus+Context via Brushing not displaying scatterplot

I'm trying to replicate this Focus+Context via Brushing example. 我正在尝试通过Brushing示例复制此Focus + Context I'm including the same layout, but with a scatterplot instead of a line/area plot. 我包括相同的布局,但使用散点图而不是线/面图。

I started working off this example I found which combines the area plot and a scatterplot. 我开始研究这个示例, 示例结合了面积图和散点图。 However, when I scrap the area plot, I lose the zoom/focus capability. 但是,当我废弃面积图时,会失去缩放/聚焦功能。

My last step (thus far unsuccessful) is to make the brush (small focus bar on the bottom) actually respond to the main panel (make it adjust/zoom in when smaller time periods are selected in the brush). 我的最后一步(因此非常失败)是使画笔(底部的小焦点栏)实际响应主面板(当在画笔中选择了较小的时间段时,使其进行调整/放大)。 The brush adjusts the axis as it should, but I just haven't been able to make the brush actually adjust/zoom the points on the main scatterplot. 笔刷会根据需要调整轴,但我只是无法使笔刷实际调整/缩放主散点图上的点。 I'm not trying plot anything in the brush - there will be a lot of points, so keeping the brush with a grey background and no points is fine. 我不打算在笔刷上画任何东西-会有很多点,因此将笔刷保持为灰色背景且没有点是好的。

here's my fiddle: http://jsfiddle.net/fuqzp580/3/ 这是我的小提琴: http : //jsfiddle.net/fuqzp580/3/

Sidenote: I can't quite get the jsfiddle to work with the way I'm using d3.csv , so I coded up a slightly altered version with dummy data in lieu of using d3.csv . 旁注:我不能完全按照我使用d3.csv的方式来使用d3.csv ,所以我用伪数据编码了一个稍作改动的版本,而不是使用d3.csv However, I included the d3.csv code (commented out), just in case that could be a cause for my problem. 但是,我包括了d3.csv代码(已注释掉),以防万一可能是造成我的问题的原因。

I'm new to d3 so any pointers or ideas welcome! 我是d3新手,欢迎任何指导或想法!

Here's an updated fiddle with the dots zooming on the points in the main panel: http://jsfiddle.net/henbox/3uwg92f8/1/ 这是一个更新的小提琴,其点放大了主面板中的点: http : //jsfiddle.net/henbox/3uwg92f8/1/

You were very close, I just made 3 small changes: 您非常接近,我做了3个小更改:

Firstly, uncommented the code you already had in function brushed() for selecting the dots 首先,取消注释您在function brushed()已经存在的用于选择点的代码

Secondly, defined mydots globally (since you were only doing it inside initialize() and it needs to be used beyond this scope). 其次,全局定义mydots (因为您只在initialize()内完成它,并且需要在此范围之外使用)。 Added this on line 55: 在第55行中添加了此代码:

var mydots = focus.append("g");

And last (and most importantly), I changed the definition for xMap from 最后(也是最重要的),我将xMap的定义从

xMap = function(d) { return x2(d.time); } 

to

xMap = function(d) { return x(d.time); } 

When brushing, it's the x scale that gets updated, not the x2 刷牙时,更新的是x比例尺,而不是x2

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

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