创建链接到 csv 文件的表
我正在尝试使用 d3 创建一个链接到 *.csv
文件的表格,但我得到的只是一个空白网页。 即使以克里米亚为例,我也会得到一个空白页。
如果有人指导或展示一个可行的例子或对我做错的事情提出建议,我将不胜感激。
I am trying to create a table linked to a *.csv
file using d3, but all I get is a blank webpage.
Even with the example Crimea I get a blank page.
I would be grateful to be directed or shown a working example or a suggestion of what I am doing wrong.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
如果您询问如何从 CSV 数据创建 HTML 表格,这就是您想要的:
查看工作示例。如果您要复制该代码,则需要更新
tabulate()
函数,以便它选择现有表或不同的容器(而不是"#container"),然后您可以将其与 CSV 数据一起使用,如下所示:
If you're asking about creating an HTML table from CSV data, this is what you want:
Check out the working example. If you're copying that code, you'll need to update the
tabulate()
function so that it either selects an existing table or a different container (rather than"#container"
), then you can use it with CSV data like so:@Shawn_allen 提出的答案中有一个错误。
要解决这个问题,只需更改以下代码行
即可
享受!
There is a bug in the answer proposed by @Shawn_allen.
To solve it just change the following line of code
by this one
Enjoy !
通常,我需要定期刷新数据表。以下是我用数据填充表格的方法:
HTML:
JavaScript:
注意:
小提琴
Often, I need to refresh a table of data periodically. Here's how I populate a table with data:
HTML:
JavaScript:
Notes:
fiddle
我很抱歉将其添加为新答案,但我没有足够的积分将其添加为评论。只需对@Shawn_Allen 代码的末尾稍加调整即可。我相信这也有效。
});
无需使用列、值创建 JSON。
I'm sorry to add this in as a new answer but I don't have enough points to add it in as a comment. Just a slight tweak to the end of the code of @Shawn_Allen. I believe that this works too.
});
There was no need to create that JSON with column, value.