- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我一直在尝试通过从 csv 文件获取数据来使用 d3.js 获取线图。我一直在尝试通过使用 csv 文件中的数据来使用 d3.js 获取线图。我收到以下错误.... [Uncaught InvalidCharacterError: Failed to execute 'setAttribute on 'Element': '0' is not a valid attribute name. ]
谁能告诉我这是什么意思以及如何纠正它?
这是我用过的代码。
<!DOCTYPE html>
<meta charset="utf-8">
<style>
body { font: 12px Arial;}
path {
stroke: steelblue;
stroke-width: 2;
fill: none;
}
.axis path,
.axis line {
fill: none;
stroke: grey;
stroke-width: 1;
shape-rendering: crispEdges;
}
</style>
<body>
<script type="text/javascript" src="d3/d3.js"></script>
<script>
var margin = {top: 30, right: 20, bottom: 30, left: 50},
width = 600 - margin.left - margin.right,
height = 270 - margin.top - margin.bottom;
var parseDate = d3.time.format("%a_%b_%d_%x__%y").parse;
// Get the data
d3.csv("Sorted Dates.csv", function(error, data) {
data.forEach(function(d) {
d.date = parseDate(d.date);
d.close = +d.close;
});
var x = d3.time.scale().range([0, width]);
var y = d3.scale.linear().range([height, 0]);
var xAxis = d3.svg.axis().scale(x)
.orient("bottom").ticks(5);
var yAxis = d3.svg.axis().scale(y)
.orient("left").ticks(5);
var valueline = d3.svg.line()
.x(function(d) { return x(d.date); })
.y(function(d) { return y(d.close); });
var svg = d3.select("body")
.append("svg")
.attr("width", width + margin.left + margin.right)
.attr("height", height + margin.top + margin.bottom)
.append("g")
.attr("transform", "translate(" + margin.left + "," + margin.top + ")"
);
// Scale the range of the data
x.domain(d3.extent(data, function(d) { return d.date; }));
y.domain([0, d3.max(data, function(d) { return d.close; })]);
svg.append("path") // Add the valueline path.
.attr(["d", valueline(data)]);
svg.append("g") // Add the X Axis
.attr("class", "x axis")
.attr("transform", "translate(0," + height + ")")
.call(xAxis);
svg.append("g") // Add the Y Axis
.attr("class", "y axis")
.call(yAxis);
});
</script>
</body>
</html>
我的 csv 文件以这种方式包含数据。这种格式正确吗? ["%a_%b_%d_%x__%y"]
1970 年 1 月 18 日星期日 07:38:02,3周日 1 月 18 日 07:39:06 1970,41970 年 1 月 18 日星期日 10:49:53,2周日 1 月 18 日 10:54:04 1970,41970 年 1 月 18 日星期日 10:55:23,4
最佳答案
您错误地将数组传递给 attr
,此处:
svg.append("path")
.attr(["d", valueline(data)]);// <-- this shouldn't be an array, just params
只需删除括号。
future 调试提示:这个错误是由 d3 抛出的,这就是为什么 Chrome 开发工具(或你使用的任何控制台)显示它来自 d3.js 源文件的原因。但是如果您在控制台中展开错误并查看堆栈跟踪,您可以在自己的代码中检测到错误。它会向您显示您自己的源代码中错误调用 d3 的 attr()
的行号,这反过来导致 d3 遇到错误。
此外,请注意,在创建 SVG 的位置,您在之后立即向其附加了一个 g
元素,这导致变量 svg
被分配给该 g
而不是实际的 SVG 元素。这不是错误;一切仍然应该有效,但这可能不是你的意思。
关于javascript - 我收到以下错误.... [Uncaught InvalidCharacterError : Failed to execute 'setAttribute' on 'Element' : '0' is not a valid attribute name,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23401288/
request.setAttribute 和 request.getSession().setAttribute() 有什么区别? 它们存储在哪里以及以什么格式? 最佳答案 区别: 当您使用reque
session.setAttribute 和 request.setAttribute 有什么区别? 最佳答案 范围,session属性住所有的session而request属性只在一个请求中 关于j
我一直热衷于重置我的一个 jsp 页面上的一些验证错误。这是一个我无法再联系到的人(死亡或无法联系)继承的项目。我有一个 jsp 页面,其中包含许多自定义标记库,其中更多页面被添加为选项卡,父页面具有
当您从请求和 getServletContext() 调用它们时,get/setAttribute() 之间有什么区别。我注意到你需要 RequestDispatcher rd = request.g
所以我正在学习操作 DOM,并且我注意到一件有趣的事情: 假设我想使用“.”设置元素的 name 属性。点符号: element.name = "someName"; console.log(docu
HttpServletRequest类的setAttribute()方法和HttpSession类的setAttribute()方法有什么区别? 在什么情况下使用? 最佳答案 一个在请求范围内设置一个
为什么我们要使用setAttribute()方法来设置ServletContext参数,因为我们可以通过在web.xml中设置参数并使用getInitParameter()来获取它们来完成相同的工作?
我在 setAttribute() 方面遇到问题。我已经搜索过互联网和这个网站,但他们没有解决我的问题。我想用 javascript 更改图片的宽度和高度,但它不起作用。请帮助我。
在学校,我的老师将我的代码更改为下面的示例它不起作用,我无法理解它是如何工作并修复它的。 function _$(e, attrs) { var el = document.createEle
我有三个元素,我正在尝试为每个元素设置属性: const foldable = document.getElementsByClassName('foldable') let result = Arr
我正在尝试使用 object3D.lookAt 属性更改图像的视角。目前我正在尝试使用组件的 update() 方法更改图像的方向。这是通过更新我的组件的 Lookat 属性来实现的。 functio
我有一些有效的 SVG 代码,可以通过在形状上设置属性来处理鼠标事件: function plot() { ... shape.setAttributeNS(null, "onmouseove
我使用的表单会根据您单击单选按钮的选项来显示一些 div。 问题是 div 设置为不显示,除非我选择一个选项。 所以我添加了以下函数,以确保如果显示 div,它将具有具有所需属性的形式。 所以我给出这
此代码嵌套在 ascx 控件中。 onclientclick 事件有效并且没有错误,但标签文本没有更改?我错过了什么?
同样,我在使用 setAttribute 时遵循我的引用书和在线引用:它根本不起作用; HTML:
这是一些 HTML: lorem Lorem, ipsum dolor sit amet consectetur adipisicing elit. Eaque magnam expedit
我一直在以不同的方式创建元素,但不确定最佳方法。有什么区别: var myselect = document.createElement("select"); myselect.name="blah"
这里我稍微修改了代码 https://www.w3schools.com/jsref/tryit.asp?filename=tryjsref_doc_getelementsbyname_loop 来自
我在为另一个元素设置属性时遇到问题。 我正在使用带有 JS 和 HTML 的 PHP 代码,它看起来像: $value 你一定知道我有两个元素。我用于编写文本的第一个('content')和另一个('
我是 Javascript 的新手,我不知道如何在选定的选项上使用 setAttribute。 我的 html 中有一个 id = employee 的 select 元素(使用 javascript
我是一名优秀的程序员,十分优秀!