# Dash 2.0 Sparkline

**URL:** <https://discourse.nodered.org/t/dash-2-0-sparkline/87814>\
**Category:** Dashboard\
**Tags:** dashboard-2\
**Created:** [7 May 2024 21:13 UTC](https://discourse.nodered.org/t/dash-2-0-sparkline/87814 "2024-05-07T21:13:23Z")\
**Posts on this page:** 5\
**Page:** 2

<div class="post-metadata">

**Author:** ![arturv2000](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/arturv2000/32/88724_2.png) [@arturv2000](https://discourse.nodered.org/u/arturv2000)\
**Post date:** [14 May 2024 00:29 UTC](https://discourse.nodered.org/t/dash-2-0-sparkline/87814/21 "2024-05-14T00:29:21Z")

</div>

@thebaldgeek Regarding the units not showing, since you have a `v-if="npm"`you need to have that variable declared in the `return` section, or just remove the `v-if="mpm"` in that case the units will always show. Something like this:

```js
<template>
  <v-card color="surface-light" max-width="600">
    <template v-slot:title>
      <div class="text-caption text-grey text-uppercase">
        EGGD VDL2
      </div>
      <span
        class="text-h3 font-weight-black"
        v-text="value[1]"
      ></span>
      <small v-if="mpm">mpm</small>
    </template>
    <v-sheet color="transparent">
      <v-sparkline :key="String(mom)" :gradient="['#f72047', '#ffd200', '#1feaea']" :line-width="3"
        :model-value="value" :smooth="16" stroke-linecap="round" auto-draw></v-sparkline>
    </v-sheet>
  </v-card>
</template>

<script>
  export default {
    data: function () {
      return {
        gradient: ['#f72047', '#ffd200', '#1feaea'],
        value: [0, 2, 5, 9, 5, 10, 3, 5, 0, 0, 1, 8, 2, 9, 0],
        mpm: true
      }
    },
    watch: {
      msg: function () {
        this.value.push(this.msg.payload)
          // Change the number to limit the array size
          while (this.value.length > 50) {
          this.value = this.value.slice(1)
        }
      }
    }
  }
</script>

<style>
.nrdb-ui-sparkline path {
  stroke-dasharray: 0 !important;
}
</style>

```

Regarding the errors and crash, it is a bit frustrating, the way I use it, is to use [vuetify play](https://play.vuetifyjs.com/) you can have the full template code there such as [example](https://play.vuetifyjs.com/#eNqFVE1v2zAM/Sucd2gKxImTru3mpQWGdehltwG7ND2oNm0LkSVDopJmRf/7aNmOncMwIFD49Z7IJyZPb5Gz2fJb0yz2HqM02hDWjRKE91sNsNnHmbA5ZEYZe7eNnLeFyDBWsqxoG0EtXuODzKni3E2SbKOAYtzAAvvYKUMpSVIdZUjncg+ZEs4xjvCV+JaGpNEQnNLisbN806DNhENm/vH4+AC/H36uN0uGj1yuEfqcrLqCwmiKD9i2Gb8oke242X3cZrloL5THp9Uzk26WLXxCVguluFIWXFc3NZfwyVVtfBhueaZRUMlViHSSiazQzGtRs0gjOZdxcKekxiEGkO7wyJBfZKUuZ7WpL7fRJFtakUvm4ZKni4/F7Tr5dHsxBzaLfJ0kwVwVKFBc8DwTYHvL6W2uzlK1yVHFQYVBjbO8q40JsNXNNO7Iml379hr5uThtjdf5tEJ4MnFuxWEIsb6ToU/69Xp1K8Zeu2PsnAnLrsusbLoqfG2MJcixEF4RvHVMuSCRQuF1FpZndjkkACySt3r0AQYlU/ivkPMRFdRhSDKH9Ryu5/AlnCv2r4LFBn9Wc/gcKjidTPG8PSmQ9XiKvXfGex84CMqqdGy0duU/RgKgSrpF6GjReFfNgs+ARSOOyoj8cixdLuF7JXSJDELQvn5BC2RAyVpSiAlrxRGc/DNZxkMlFULH292jUJdUwT1cJ2etTJuBu2lnTskMZ6tJL/3E48zdN4f5hzW8cfvedOz/JBba5i+xl+PuQCO4jb6BfhNz4aowRQoJfJB1uyJC09eRvCeM3ufaKxWO57/x5oKp).  
It is a fast way to check for errors, it happens to me all the time to forgot that in same places i need to use `value: 55,` instead of `value = 55;` or vice-versa for example.

It is not possible to simulate "msg" and we cannot also use the `this.send` to simulate messages, normally I use `console.log` or `alert` to simulate messages being sent from the template to NodeRed to validate stuff. Regarding `msg` sometimes just define a timeout to run every second and a function to emulate "data".

---

<div class="post-metadata">

**Author:** ![thebaldgeek](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/thebaldgeek/32/93523_2.png) [@thebaldgeek](https://discourse.nodered.org/u/thebaldgeek)\
**Post date:** [14 May 2024 01:37 UTC](https://discourse.nodered.org/t/dash-2-0-sparkline/87814/22 "2024-05-14T01:37:16Z")

</div>

Thanks for the fix @arturv2000

As I mentioned in the post with the code snip I also find the Vuetify play area, as you said, its a quick pain free way to break and fix quicky.  
The lack of msg.payload inputs is very limiting. The weird thing is that I got the mpm working in the play area, but not in my template, so clearly my cut/paste skills are as lacking as my 'low code' skills \< grin \>

My next two goals for the sparkline is to make it smaller. Its just huge and I miss the whole compact aspect of the sparkline.  
The second is to get it working in a table.  
I'd like to see 4-5 in a single table with the data values.  
I see the example here: [https://flowfuse.com/blog/2024/04/dashboard-milestones-pwa-new-components/#sparkline-(docs)](https://flowfuse.com/blog/2024/04/dashboard-milestones-pwa-new-components/#sparkline-(docs)) But am unable to get it working.

---

<div class="post-metadata">

**Author:** ![arturv2000](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/arturv2000/32/88724_2.png) [@arturv2000](https://discourse.nodered.org/u/arturv2000)\
**Post date:** [14 May 2024 06:20 UTC](https://discourse.nodered.org/t/dash-2-0-sparkline/87814/23 "2024-05-14T06:20:02Z")

</div>

HI  
Regarding the playground, sometimes the rendering is not exactly the same also because off css styles defined in dashboard that change some components behaviours .

I used that example as base for my project, remenber that there where some issue, don't remenber exactly which one.

Don't have access to the work pc at the moment, will try to post an example when arrive at work.

---

<div class="post-metadata">

**Author:** ![arturv2000](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/arturv2000/32/88724_2.png) [@arturv2000](https://discourse.nodered.org/u/arturv2000)\
**Post date:** [14 May 2024 09:16 UTC](https://discourse.nodered.org/t/dash-2-0-sparkline/87814/24 "2024-05-14T09:16:07Z")

</div>

Here a small example of a table with the sparklines.

The handling of the array is done externally, since for my use want to preserve the history even upon page reloading and wasn't happening with the template.

```auto
[{"id":"ead3ae3670afa3c8","type":"inject","z":"33f272716c862133","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"0.5","crontab":"","once":true,"onceDelay":0.1,"topic":"newValue","payload":"","payloadType":"date","x":560,"y":4440,"wires":[["9765f18dec0445ea"]]},{"id":"9765f18dec0445ea","type":"function","z":"33f272716c862133","name":"Parse WideBands","func":"if(msg.topic != 'clear' && msg.topic != 'newValue'){\n return null;\n}\n\nlet _oldData = context.get('data') ?? undefined;\n\nlet _value = [Math.floor(Math.random() * 100), Math.floor(Math.random() * 100)];\n\n\nif(_oldData == undefined || msg.topic == 'clear'){\n _oldData = [];\n _oldData.push({ channel: 1, name: 'EGT1', value: (_value[0]), arrayvalues: [(_value[0])], unit: 'ºC'});\n _oldData.push({ channel: 2, name: 'EGT2', value: (_value[0]), arrayvalues: [(_value[0])], unit: 'ºC' });\n}else{\n for(let i = 0; i < 2; i++){\n _oldData[i].value = (_value[i]);\n _oldData[i].arrayvalues.push(_value[i]);\n if (_oldData[i].arrayvalues.length > 50) {\n _oldData[i].arrayvalues.shift();\n }\n }\n}\n\ncontext.set('data', _oldData);\n\nreturn {topic: 'data', payload: _oldData};\n\n\n","outputs":1,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[],"x":830,"y":4440,"wires":[["7af90e299d5aee5e","62c16319ce066dd8"]]},{"id":"62c16319ce066dd8","type":"ui-template","z":"33f272716c862133","group":"acbbafbfc6d6007a","name":"Table Test","order":3,"width":0,"height":0,"head":"","format":"<template>\n <!-- Provide an input text box to search the content -->\n <div class=\"d-flex\" style=\"font-weight: bold; font-size: 1.3rem\">\n <span class=\"text-center\" style=\"width: 100%\"> Generic Temperatures </span>\n <v-spacer></v-spacer\n ><v-btn color=\"#D2691E\" @click=\"this.send({topic: 'clear'})\">\n <strong style=\"color: white\">Clear</strong>\n </v-btn>\n </div>\n <v-data-table class=\"myDataTable\" :items=\"msg?.payload\" :headers=\"headers\" hide-details=\"auto\" density=\"compact\" items-per-page=20>\n <template #bottom>\n <!-- Leave this slot empty to hide pagination controls -->\n <!-- <hr> -->\n </template>\n <template v-slot:item.value=\"{ item }\">\n <v-progress-linear :model-value=\"getValue(item.value)\" max=\"100\" height=\"40\" :color=\"getColor(item)\">\n <template v-slot:default=\"{ value }\">\n <strong>{{ Math.ceil(item.value) }}{{item.unit}}</strong>\n </template>\n </v-progress-linear>\n </template>\n <template v-slot:item.arrayvalues=\"{ item }\">\n <v-sparkline v-model=\"item.arrayvalues\" :gradient=\"['#FF0000', '#5525FF']\" :line-width=\"1\" gradientDirection=\"top\"\n :smooth=\"true\" :fill=\"false\" height=\"45\">\n </template>\n\n </v-data-table>\n</template>\n\n<script>\n export default {\n data () {\n return {\n progressBar_Max: 100,\n progressBar_Min: 0,\n headers: [\n { key: 'name', title: 'Name', width: '15%'},\n { key: 'value', title: 'Value', width: '45%', align: 'center' },\n { key: 'arrayvalues', title: 'History',align: 'center' }\n]\n }\n },\n methods: {\n getColor: function (item) {\n if (item.value > 80) {\n return 'red'\n } else {\n return 'green'\n }\n },\n // add a function to determine the color of the progress bar given the row's item\n getValue: function (value) {\n let val = Math.ceil(this.map(value, this.progressBar_Min, this.progressBar_Max, 0, 100));\n return val;\n },\n map: function (current, in_min, in_max, out_min, out_max){\n let mapped = ((current - in_min) * (out_max - out_min)) / (in_max - in_min) + out_min;\n return this.clamp(mapped, out_min, out_max);\n },\n clamp: function (input, min, max) {\n return input < min ? min : input > max ? max : input;\n }\n }\n}\n</script>\n<style>\n .v-progress-linear __determinate {\n transition: none !important\n }\n\n .myDataTable .v-data-table-header__ content {\n font-weight: bold;\n }\n</style>","storeOutMessages":true,"passthru":true,"resendOnRefresh":true,"templateScope":"local","className":"","x":1060,"y":4440,"wires":[["a375d22722bd6d24","9765f18dec0445ea"]]},{"id":"acbbafbfc6d6007a","type":"ui-group","name":"WideBand Probe","page":"3cdf194d3e1f3330","width":"6","height":"1","order":6,"showTitle":true,"className":"","visible":"true","disabled":"false"},{"id":"3cdf194d3e1f3330","type":"ui-page","name":"Values Visualization","ui":"9df4836d2f5c3db3","path":"/values_view","icon":"chart-timeline","layout":"grid","theme":"6abc079232f2e7a5","order":6,"className":"","visible":"true","disabled":"false"},{"id":"9df4836d2f5c3db3","type":"ui-base","name":"My Dashboard","path":"/dashboard","includeClientData":true,"acceptsClientConfig":["ui-notification","ui-control"],"showPathInSidebar":false,"navigationStyle":"default"},{"id":"6abc079232f2e7a5","type":"ui-theme","name":"Default Theme","colors":{"surface":"#097479","primary":"#097479","bgPage":"#111111","groupBg":"#333333","groupOutline":"#cccccc"},"sizes":{"pagePadding":"6px","groupGap":"6px","groupBorderRadius":"4px","widgetGap":"6px"}}]

```

It is still a work in progress...

---

<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:** [13 June 2024 09:16 UTC](https://discourse.nodered.org/t/dash-2-0-sparkline/87814/25 "2024-06-13T09:16:16Z")

</div>

Closed on 13 June 2024 09:16 UTC

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

[Previous page](https://discourse.nodered.org/t/dash-2-0-sparkline/87814.md?page=1)
