D3JS数据加载和更新 [英] D3JS data load and update

查看:738
本文介绍了D3JS数据加载和更新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用D3JS库来加载名为data.csv的CSV数据。通过点击按钮,我在控制台上输出数据长度。
我的问题是,如果我更改了data.csv中的两个动作之间的数据,按钮上的数据不会更新。

I am using D3JS library in order to load a CSV data named "data.csv". By clicking on the button, I output on the console the data length. My problem is that if I change the data inside "data.csv" between two actions on the button, the data won't update.

,我有一个CSV与100数据和另一个与200.首先,我把我的100数据CSV在我的文件夹,并按读取按钮,我可以检查控制台的数据长度,它是如预期的数据长度= 100。之后,我用200个数据覆盖CSV文件,再次按下按钮,控制台仍然显示相同的数据长度(100),我的数据变量没有更新与新文件中的新数据。

For example, I have one CSV with 100 data and another one with 200. Firstly I put my 100 data CSV in my folder and press the "Read" button, I can check on the console the data length, it is as expected "Data length = 100". After that, I overwrite the CSV file with the 200 data one and press the button again, the console still displays the same data length (100), my data variable has not been updated with the new data from the new file.

如何解决我的数据更新问题?

How can I solve my data update problem ?

HTML

<button onclick="read_data()">Read</button>

JavaScript

function read_data(){
    Plotly.d3.csv("data.csv", function(error, data) {
        console.log("Data length = " + data.length)
    })
}


推荐答案

像Andrew指出,浏览器可能正在缓存文件。也许你可以添加查询参数,例如:

Like Andrew pointed out browser might be caching the file. Maybe you could add query parameter, for example:

function read_data(){
     Plotly.d3.csv("data.csv?"+(new Date()).getTime(), function(error, data) {
         console.log("Data length = " + data.length)
 })}

这篇关于D3JS数据加载和更新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆