Open escoand opened 9 years ago
Could you give an example or jsfiddle?
I have a website with multiple graphs but you can just show some accoding to your rights. If you haven't the right to show on graph the backend is not generating a csv with return code 200 but return code 401. An other example is when the backend has a problem and is responding with http return code 500 or whatever.
The broader question here is how much dygraphs wants to be in the business of managing your network connections and data processing. My answer has always been "not at all." If you want to do something fancier, use jQuery or some other library to issue XHRs and pass the data directly to the new Dygraph
constructor.
OP's request is absolutely justified (but I don't see how you can just add a method/property to something to solve this -- it's more complicated than that). That said:
Given that Dygraphs issues XHRs itself -- supporting URLs for data sources, incl. updateOptions() -- "use jQuery or some other library" as a rebuttal borders on offensive. What's needed is a callback point for the XHR listener (ProgressEvent) events "error" and "timeout" (I would strongly suggest the XHR object be available to the callback so that things like HTTP status code, etc. can be obtained).
A use case is easy to understand, and one that has come up many times in my years of using Dygraphs: in cases where updateOptions() is called with a new file (URL), and the URL cannot be fetched (e.g. 4xx/5xx cases), the previous/old graph remains on-screen.
I know error handling is hard and complicated. But given that Dygraphs is a monolithic solution for "graphing data" and controls/wraps every aspect of the visually rendered result area -- rephrased: "new Dygraphs" + hope for the best is all the developer can do -- I feel that does put the responsibility on Dygraphs.
Currently there is no way to know if the data was loaded if the http return code is unequals 200 - maybe .failure() or .error() Or maybe a more generic approach like http://api.jquery.com/jQuery.get/