-
Notifications
You must be signed in to change notification settings - Fork 13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Best practice for adding/removing series/data dynamically #32
Comments
Hi there, Sorry for the late reply, was a bit busy recently. As for the errors - I couldn't reproduce it. If you have a minimally reproducible test-case, feel free to share it, I will take a look. |
Hi and thank you for not so late reply:-) Yes I have tried both using graph props and API, but I get errors when adding or deleting series/data in both cases.
When I close the react error layer, then the graph seems to have been drawn correctly according to the update. I'll try to see if I can make a stand alone repro of the problem. It would also help me developing extra features we need. Best regards from Peter |
I have succeeded recreating the error I encount when using prop changes. In line 159 you can in-comment the second y series data array which solves the error. It would be nice if the data element was not mandatory. The other way around seems to work, where theres more data series than series option definintion. Maybe I can add a dummy data element as workaround. |
I see. Yeah, it seems to be working that way. You have to add data series first, option series second. When removing do the opposite: remove option series first, then data series. As a w/a you can add an empty array, if you want to display the series when there is no data. Btw I also saw you other comment here leeoniya/uPlot#962 I think you should re-phrase the question a bit, since there are so many problems packed in one issue, it makes it very difficult to understand. Probably that's why there is no reply yet... Maybe it would be better to make it all about the updateSeries feature w/o mentioning React and all? If we have an updateSeries by key method, we can use it in the wrappers and all the mentioned problems will be automatically resolved. |
Closing then. Will return to it when/if there is API in uPlot to work with series by keys. |
Hi
I'm enjoying the uPlot graph API and the React wrapper, thank you for the nice work.
I have a need for adding/deleting series to a graph dynamically, and I'm wondering what the best approach would be.
I can update the data and option props on the component which seems to re-render the graph, but it also resets things like graph selection in the legend, and often i get uPlot errors "cannot read .. of undefined" which seems to be related to axis generation . The wrapped uPlot may be very sensitive to what is added first; series og data, or maybe these errors is related to some other problem down the pipe.
In add/del series example it is done using the methods on the uPlot object, .addSeries .delSeries but then i have to manage the state separately to know my current series. And it seems to break the React way of using state changes for auto updating the component. But updating the option and data props seems to cause full delete/recreate of the graph which is not optimal. So I'm in doubt how to work this one out?
Some advice here would be highly appreciated.
Thanks from Peter, Denmark
The text was updated successfully, but these errors were encountered: