Save&Restore Chart Data

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:

Now I want to mix both features:

  1. Store chart data manually (e. g. using the inject node)
  2. 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

Hi, I have used the same solution with a small upgrade, in the chart I have set a period of 24 hour. I create a txt file for every day for the chart.

This seems to be helpful as well:

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.

    contextStorage: {
      default: "memoryOnly",
    memoryOnly: { module: 'memory' },
          file: { module: 'localfilesystem',
          config: {
                  flushInterval: '1200'

Sounds as this is exactly what I‘m looking for. I‘ll give it a try tomorrow...

1 Like

I think I got it. Did it that way:

First: Changed file "settings.js" as suggested by Paul-Reed.

My node...

Setup of my inject node, with restore from memoryOnly and
setup of my change node, with storage to memoryOnly:

You should be saving and restoring if from file not memory.
If you use memory and reboot your pi, all data will be lost.

1 Like

The chart data files should be stored in...



Will the flush (copy memory content to file) be triggered if I'll deploy my workspace (Full Deploy)?

That's what the docs say...

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).

I've changed it as suggested by Paul-Reed:

Now the chart data is stored & restored as expected.
Thanks to everybody for helping me!

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.