Skip to content
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

Bar chart incorrect history load #753

Open
Martin12350 opened this issue Apr 6, 2024 · 4 comments
Open

Bar chart incorrect history load #753

Martin12350 opened this issue Apr 6, 2024 · 4 comments
Labels
bug Something isn't working size:S - 2 Sizing estimation point

Comments

@Martin12350
Copy link

Current Behavior

When the page is refreshed and a bar chart loaded from history, it ignores the order of the bars.
On the start, I clear the chart and fill series with labels and values with zeros. When the appropriate series arrives, it correctly shows the value for the correct bar. However, when the page is refreshed, the bars are weirdly reordered.

NR.bar.chart.mp4

Expected Behavior

The order of bars should persist across refreshes.

Steps To Reproduce

Flow to reproduce
Test flow.json

Environment

  • Dashboard version: 1.7.1
  • Node-RED version: 3.1.8
  • Node.js version: 18.19.0
  • npm version: 10.2.3
  • Platform/OS: Linux RPi
  • Browser: Firefox and Chrome

Have you provided an initial effort estimate for this issue?

I am not a FlowFuse team member

@Martin12350 Martin12350 added bug Something isn't working needs-triage Needs looking at to decide what to do labels Apr 6, 2024
@m-schaeffler
Copy link
Contributor

I'm suffering on the same issue.

@Martin12350
Copy link
Author

If You want, I have a "hacky" solution. But! note that this way, it refreshes the whole chart every time it gets a new value, so if You are using phone data and have a big chart with a fast refresh rate, it will chew your data out in no time.

In the chart set series to key: bar and y to key: value. You can change those names obviously.
And before the chart, create a function with this code:

var data = context.get("data") || [];

//init data if does not exist yet
if (data.length === 0)
    for (var i = 0; i < 60; i++) {
        const bar = ("0" + i).slice(-2) + ".";
        data.push({ bar, value: 0 });
    }

//update value
var index = data.findIndex(d => d.bar == msg.bar);
if (index != -1) data[index].value = msg.payload;
 
context.set("data", data);
msg.payload = data;
return msg;

It is pretty self-explanatory, but in any case, the code stores all the chart data in context, and when a message arrives with a bar value, it finds its column, updates the value, saves it in context, and sends it to the chart.

Btw. when setting the series to JSON, something similar happens - it always expects all the data and redraws the whole chart.
It would be really cool if it would just init the chart on the first time and then updates the columns depending on the payload.
Now, if any value is missing in the payload, but is specified in the series, it treats it as 0.

@joepavitt joepavitt added size:S - 2 Sizing estimation point and removed needs-triage Needs looking at to decide what to do labels Apr 18, 2024
@m-schaeffler
Copy link
Contributor

@Martin12350 Yes: this is a kind of workaround

But it happens also with line diagrams!
If you press several times F5 to reload the page, sporadically the sequence of the lines in the legend is changed and so the colors of the lines are exchanged.

@Martin12350
Copy link
Author

I have also a cool proposition, but that should be probably in another thread.
When passing a new value to the chart, it could check for msg.options, where could be specified options for that specific value, such as color of the bar, color of the line, line width for the segment etc.
It is similar idea, that somebody already mentioned as advanced config (#58), but the difference is, it would be specific to the value, not the whole chart. That way we could have multicolored charts based on value, instead of the group.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working size:S - 2 Sizing estimation point
Projects
Status: Up Next
Development

No branches or pull requests

3 participants