- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试实现 D3 的动态功能,为此我遵循了 http://mbostock.github.io/d3/tutorial/bar-2.html 中给出的示例它工作正常,但是当我为 x 轴和 y 轴添加代码时,我从 redraw() 函数中收到“NotFoundError: Node was not found”错误。
没有轴绘制的代码,它工作正常,但从 redraw() 函数中得到“NotFoundError: Node was not found”错误。
让我知道问题是什么以及如何解决。 -- 谢谢
//Data set
var t = 17;
var data = [
{"time": 1, "value": 56, "color": "green"},
{"time": 2, "value": 53, "color": "green"},
{"time": 3, "value": 58, "color": "green"},
{"time": 4, "value": 58, "color": "green"},
{"time": 5, "value": 56, "color": "green"},
{"time": 6, "value": 53, "color": "green"},
{"time": 7, "value": 58, "color": "red"},
{"time": 8, "value": 58, "color": "red"},
{"time": 9, "value": 56, "color": "green"},
{"time": 10, "value": 53, "color": "green"},
{"time": 11, "value": 58, "color": "green"},
{"time": 12, "value": 58, "color": "green"},
{"time": 13, "value": 56, "color": "orange"},
{"time": 14, "value": 53, "color": "green"},
{"time": 15, "value": 58, "color": "orange"},
{"time": 16, "value": 58, "color": "green"}
];
var minval = 0,
maxval = 100,
sumval = 0,
sampsize = 30;
var max = 4, min = 0;
//var label_array = new Array();
var val_array = new Array(),
val_array_sum = new Array(),
data_array = new Array(),
val_array_stackedbar = new Array();
sampsize = data.length;
function next() {
return {
time: ++t,
value: 60,
color: "green"
};
}
setInterval(function() {
data.shift();
data.push(next());
redraw();
}, 1500);
var width = 300, height = 300, height2 = 5;
var margin = {
top : 30,
right : 10,
bottom : 40,
left : 60
}, width = width - margin.left - margin.right, height = height
- margin.top - margin.bottom;
// create the graph object
var vis = d3.select("#stackedbar-chart3")
.append("svg:svg")
.attr("class", "metrics-container3")
.attr("width", width + margin.left + margin.right)
.attr("height", height + margin.top + margin.bottom);
// .append("g").attr(
// "transform",
// "translate(" + margin.left + ","
// + margin.top + ")");
var y = d3.scale.linear().domain([0, maxval]).range([height, 0]);
var x = d3.scale.linear().domain([0, sampsize+1]).range([0, width]);
var y2 = d3.scale.linear().domain([0, maxval]).range([0, height]);
var yAxis = d3.svg.axis().scale(y).orient("left")
.ticks(5);
var xAxis = d3.svg.axis().scale(x).orient("bottom")
.ticks(5);
// Add first data-series
var bars = vis.selectAll("rect")
.data(data)
.enter().append("svg:rect")
.attr("fill", function(d) { return d.color; } )
.attr("x", function(d, i) { return x(i+1); })
.attr("y", function(d, i) { return height - y2(d.value); } )
.attr("width", 5)
.attr("height", function(d, i) { return y2(d.value); });
现在添加轴
// Add x-axis and y-axis
vis.append("g").attr("class", "axis").call(yAxis);
vis.append("g").attr("class", "axis").attr("transform",
"translate(0," + height + ")").call(xAxis);
// Add the axes labels
vis.append("text").attr("class", "axis-label").attr(
"text-anchor", "end").attr("x", 20).attr("y",
height + 34).text('Time');
重绘功能用于使图表动态化
function redraw() {
var bars = vis.selectAll("rect")
.data(data, function(d) { return d.time; });
bars.enter().insert("rect", "line")
.attr("fill", function(d) { return d.color; } )
.attr("x", function(d, i) { return x(i+1); })
.attr("y", function(d, i) { return height - y2(d.value); } )
.attr("width", 5)
.attr("height", function(d, i) { return y2(d.value); })
.transition()
.duration(1000)
.attr("x", function(d, i) { return x(i) - .5; });
bars.transition()
.duration(1000)
.attr("x", function(d, i) { return x(i) - .5; });
bars.exit().transition()
.duration(1000)
.attr("x", function(d, i) { return x(i - 1) - .5; })
.remove();
}
最佳答案
您的代码无法正常工作,因为用于插入新柱的行已不存在。即代码
bars.enter().insert("rect", "line")
不工作,因为没有 line
元素。您可以通过简单地附加新条来解决这个问题。修改后的 jsfiddle here .
关于javascript - D3 错误 : NotFoundError: Node was not found,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18484501/
我正在尝试使用python从elastisearch索引中检索文档。其代码如下: def get_data_es(): ES_HOST = { "host": "loc
我想在 Python 中使用 ElasticSearch 从给定的 URL(带有前缀)获取数据。这是我的代码: if __name__ == '__main__': username = "x
我现在很困惑,因为我通过添加“from mechanize import ControlNotFoundError”修复了一个错误。但是,它现在弹出此错误。任何帮助是极大的赞赏。我几天前才开始学习 p
我已经训练 TensorFlow 模型大约一周时间,偶尔进行微调。 今天,当我尝试微调模型时,出现错误: tensorflow.python.framework.errors_impl.NotFoun
代码: import pandas as pd import quandl quandl.ApiConfig.api_key = 'wsnt2aKcnkNMJjdqqwTz' pd = quandl.
我在请求范围内设置了一个employeebean resultEmployeeList 的数组列表。我不知道我是否以正确的方式这样做..但这里是jsp中使用的jSTL代码..
我正在尝试实现 D3 的动态功能,为此我遵循了 http://mbostock.github.io/d3/tutorial/bar-2.html 中给出的示例它工作正常,但是当我为 x 轴和 y 轴添
我在适用于 Linux 的 Windows 子系统的 Ubuntu 16.04 版本中使用 Tensorflow 1.14.0(通过 pip 安装)和 Python 2.7。我正在运行另一个人编写的脚
我正在尝试复制在时间序列中使用 RNN 的示例,如发布的 https://www.tensorflow.org/beta/tutorials/text/time_series#multi-step_m
当我使用以下方法恢复保存的模型时: checkpoint = tf.train.get_checkpoint_state(config.pre_model_dir) if checkpoint and
我在使removeChild()工作时遇到问题。我收到“NotFoundError:未找到节点 image_div.parentNode.removeChild(img);”错误 这是我的代码:
我正在 HTML5 中进行拖放操作,但是当我 dorp 我的项目时,我遇到了 Uncaught Error: NotFoundError: DOM Exception 8 任何人都可以帮助我。请检查下
我刚刚安装了基于 tf.__version__ = 1.14 的新环境。 以下是我配置张量板的方式: tensorboard = \ tf.keras.callbacks.TensorBoar
我使用以下代码使用 tensorflow 创建自定义初始。 import tensorflow as tf import sys interesting_class = sys.argv[1:] pr
我想我会喜欢并在 jQuery 事件期间使用普通 JavaScript。这个想法是,在单击标题时,我想向上滑动一个 div (可以工作)并将单击的标签替换为更大的标题。 根据我所读到的内容,这可能是由
收到此错误: # rails c FFI::NotFoundError: Function 'xmlRelaxNGSetParserStructuredErrors' not found in [li
问题:将 numpy 链接到正确的线性代数库。过程非常复杂,我可能会第六次寻找解决方案,但我不知道出了什么问题。我在 Ubuntu 12.04.5 上。 我重新安装了 blas 和 lapack,然后
我有一个 div里面另外三个div s 附加如下。状态值是通过循环来自 componentWillReceiveProps() 的 api 的结果来设置的。 .但我面临一个错误问题 Uncaught
无法真正描述为什么这不起作用。 我确实有 JS 对象控制一些数据,每个控件也有一个 HTML 对象。该对象存储在数组中。我在很多项目中都这样做过几次,但现在在使用 jQuery 的“wrapAll”时
我正在使用 retrain.py 在我的手部照片上重新训练对象检测器(以检测我握着多少根手指)。在 Tensorflow 网站上,我按照教程在花朵图像上对其进行了重新训练。所以我写了 python r
我是一名优秀的程序员,十分优秀!