- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我使用的代码与 http://techanjs.org/ 中使用的代码几乎相同.我试图在图表中添加缩放功能,因为开发人员已在 here 中呈现图表。 .但不知何故我无法缩放它。我收到错误选择未在控制台中定义。我正在使用以下代码来呈现图表。 https://paste.fedoraproject.org/paste/7gJq9wKL4h4s862EDuxnQQ .我确定我在这里做错了什么,如果我能得到任何帮助,我将不胜感激,因为我仍在学习 D3。
最佳答案
我猜问题是您正在引用变量 selection
但它未定义。
因此 -
selection is not defined
selection
是传递给您的 bigchart
函数的参数。
但是您随后在未定义它的reset
、zoomed
函数中使用它。
//Zoom Begins
function reset() {
zoom.scale(1);
zoom.translate([0,0]);
selection.call(draw); // this will throw an error
}
function zoomed() {
x.zoomable().domain(d3.event.transform.rescaleX(zoomableInit).domain());
y.domain(d3.event.transform.rescaleY(yInit).domain());
yPercent.domain(d3.event.transform.rescaleY(yPercentInit).domain());
selection.call(draw); // this will throw an error
}
//Zoom Ends
要解决这个问题,要么将选择作为参数传递给函数(就像其他函数一样)- 或者使 selection
成为 BigChart
的属性,这样它就可以由 reset
和 zoomed
函数引用。
即
// pass selection to the functions as a parameter
function reset(selection) {
zoom.scale(1);
zoom.translate([0,0]);
selection.call(draw);
}
function zoomed(selection) {
x.zoomable().domain(d3.event.transform.rescaleX(zoomableInit).domain());
y.domain(d3.event.transform.rescaleY(yInit).domain());
yPercent.domain(d3.event.transform.rescaleY(yPercentInit).domain());
selection.call(draw);
}
然后当你调用这些函数时,显然你传入了正确的对象......例如
zoom = selection.call(d3.zoom().on("zoom", zoomed));
而不是
zoom = d3.zoom().on("zoom", zoomed),
关于javascript - 无法缩放 d3 techanjs,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47742282/
我使用的代码与 http://techanjs.org/ 中使用的代码几乎相同.我试图在图表中添加缩放功能,因为开发人员已在 here 中呈现图表。 .但不知何故我无法缩放它。我收到错误选择未在控制台
我想在我的应用程序中使用几个 techanJS 示例,但很难使用我自己的数据。 这是example code for the close chart我想用它。 我有戏!传入 List[CloseLis
我是一名优秀的程序员,十分优秀!