# Chart Ymax buffer based on payload

**URL:** <https://discourse.nodered.org/t/chart-ymax-buffer-based-on-payload/47086>\
**Category:** General\
**Created:** [12 June 2021 23:32 UTC](https://discourse.nodered.org/t/chart-ymax-buffer-based-on-payload/47086 "2021-06-12T23:32:37Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![jjcfrank](https://avatars.discourse-cdn.com/v4/letter/j/d6d6ee/32.png) [@jjcfrank](https://discourse.nodered.org/u/jjcfrank)\
**Post date:** [12 June 2021 23:32 UTC](https://discourse.nodered.org/t/chart-ymax-buffer-based-on-payload/47086/1 "2021-06-12T23:32:37Z")

</div>

Hello everyone,

I have a chart that has no margins and so if I have a high value it shows right at the top. **Is there a way to add 10 points/values to the incoming value so I get a bit of a buffer?**

I tried using "msg.ui\_control.ymax = msg.payload + 10" but did not work.

I have been searching throughout the internet but have not found anything specific.

Thanks!

---

<div class="post-metadata">

**Author:** ![leftymuller](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/leftymuller/32/102326_2.png) [@leftymuller](https://discourse.nodered.org/u/leftymuller)\
**Post date:** [13 June 2021 06:36 UTC](https://discourse.nodered.org/t/chart-ymax-buffer-based-on-payload/47086/2 "2021-06-13T06:36:58Z")

</div>

Put a debug on it and make sure its a number would be a good start 🙂

---

<div class="post-metadata">

**Author:** ![jjcfrank](https://avatars.discourse-cdn.com/v4/letter/j/d6d6ee/32.png) [@jjcfrank](https://discourse.nodered.org/u/jjcfrank)\
**Post date:** [13 June 2021 07:24 UTC](https://discourse.nodered.org/t/chart-ymax-buffer-based-on-payload/47086/3 "2021-06-13T07:24:33Z")

</div>

Thanks. It is indeed! Chart is working fine. I just need a bit of a buffer. I'd like the height of the chart be dependent on a combination of the reading + 10 (this is the buffer)

---

<div class="post-metadata">

**Author:** ![leftymuller](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/leftymuller/32/102326_2.png) [@leftymuller](https://discourse.nodered.org/u/leftymuller)\
**Post date:** [13 June 2021 07:52 UTC](https://discourse.nodered.org/t/chart-ymax-buffer-based-on-payload/47086/4 "2021-06-13T07:52:37Z")

</div>

msg.payload = msg.ui\_control.ymax+10

give that a whirl

---

<div class="post-metadata">

**Author:** ![jjcfrank](https://avatars.discourse-cdn.com/v4/letter/j/d6d6ee/32.png) [@jjcfrank](https://discourse.nodered.org/u/jjcfrank)\
**Post date:** [13 June 2021 08:42 UTC](https://discourse.nodered.org/t/chart-ymax-buffer-based-on-payload/47086/5 "2021-06-13T08:42:19Z")

</div>

This was helpful. I have tried implementing it but something odd happened. So the Ymin works as expected, the reading was 25 and I set the Ymin to (reading - 5) and it set the Ymin as 20. Perfect.

However, the Ymax does something strange. When I do the same, for some odd reason, NR add the number to the end of the reading, i.e. if I have 25 + 1, NR renders this as 251! See screenshots.

Any thoughts?

The flow:  
 ![Screenshot 2021-06-13 at 09.15.02](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/b/3/b3cd20a4b7f73f7d9b492cf5e1a1c9a55924293f.png)

The function that leads to the chart:

 ![Screenshot 2021-06-13 at 09.38.19](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/a/5/a58ad6b0a6ea89575f753e9cb4d81b90449b43d9.png)

The chart at the moment  
 ![Screenshot 2021-06-13 at 09.38.31](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/a/f/af5d6437431bd6285acad7be82c6bfb8eff40cf6.png)

---

<div class="post-metadata">

**Author:** ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)\
**Post date:** [13 June 2021 09:11 UTC](https://discourse.nodered.org/t/chart-ymax-buffer-based-on-payload/47086/6 "2021-06-13T09:11:03Z")

</div>

then as leftymuller hinted your msg.payload is probably a string "25" not a numeric 25... so "25" +1 is concatenated to "251".... One of the joys of Javascript. Use parseFloat to try to make it a number

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [12 August 2021 09:11 UTC](https://discourse.nodered.org/t/chart-ymax-buffer-based-on-payload/47086/7 "2021-08-12T09:11:48Z")

</div>

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