I had the problem that my chart data was deleted when I deployed my workspace. I was able to solve this topic using this subflow:
But I'm wondering if my file system will be damaged if there is a periodically (every minute = 1440 times a day) access to the file system (USB stick or SD card). Therefore I tried to add a feature to save the chart data manually, before I'll deploy my workspace. And I found this example: https://flows.nodered.org/flow/92920b4fd450bf92a3035e061947daa0
Now I want to mix both features:
Store chart data manually (e. g. using the inject node)
Load data automatically
As I am a Node-RED rookie, I need some help to implement that!
Since no-one else has answered I will jump in here. If you use the subflow you mention then you can easily limit how often it writes by putting a Delay node configured something like this to limit often it saves the chart
Alternatively, if you use a Trigger node configured as below then it will do the same thing but has the advantage that you could send it a reset message which would reset it so the next time the chart sends it current state that would get through immediately, giving you your 'save on demand' feature, or at least a 'save on next update'
I haven't looked at the subflow but if it uses a file for storage then that is no longer the easiest way of doing this. The best way now would be to use persistent context store. See the docs on Working with Context
Why not use node-RED's inbuilt file based context to save/restore your chart, it's easy to setup and uses 2 standard nodes.
See Working with context : Node-RED to set up file context, then add a change node to the output of your chart to save the chart data to your file context.
Then add an inject node to inject the file context into the chart node
Set the inject node just to inject once
If you are concerned about continually writing data to the file system, you can then edit your contextStorage settings, and add the flushInterval value, to only write data to your file system every, for example 1200 seconds (the example below) OR if you stop node-RED it will also write it.
So although your chart updates every minute, the chart data will be initially saved to memory, but then node-RED will flush it to the filesystem as per the flushInterval.
There would be no need to 'flush the data to file' for a full deployment, as the chart will retain it's data anyway when a full deployment is made.
Are you saying that your chart doesn't?
I believe that a flush occurs when either node-RED is stopped, when the OS is shutdown, or the time listed in flushInterval is reached (and then only if the data has actually changed).