Uibuilder add Apex chart bar

Hi folks,

I'm trying to build with uibuilder and Vue.
For now, the uibuilder web is running ok with the values of 3 variables incoming from Node-Red.
In the bottom a simple visibility animation with text is included, wich I need to change text to image.

Now, I would like to add an Apex Bar Chart. Only 1 vertical bar, with CO2 value.
I have tested some samples on github with succes, but I'm unable to make it run in my web.

Below is Node-Red flow:

[{"id":"4ed47256.7415cc","type":"tab","label":"GIRONA TEST","disabled":false,"info":""},{"id":"3a85e836.06b698","type":"comment","z":"4ed47256.7415cc","name":"uibuilder/Simple Example","info":"[Front-End](/uib_simple)\n\nThis flow gets a \"quote of the day\" from the Internet and passes it\nto uibuilder. It caches the result so that if you reload the page,\nyou get the last result back. The quote is updated every 30 minutes\nduring the day and evening.\n\n\"Simple\" refers to the front-end code. While the flow looks a little\ncomplex, it really isn't. A trigger (repeating), an Internet request,\na cache and uibuilder. The link nodes loop the control output from\nuibuilder back to the cache.\n\n## Configuration\n\nUpdate the files:\n\n* `index.html`\n* `index.js`\n* `index.css`\n\nAccording to the example(s) in the 3 other comment nodes in this example.\n\nPress the button on the trigger to start the flow.","x":450,"y":140,"wires":[]},{"id":"7cf5c3b2.96006c","type":"comment","z":"4ed47256.7415cc","name":"index.html","info":"<!doctype html><html lang=\"en\"><head>\n    <meta charset=\"utf-8\">\n    <meta http-equiv=\"X-UA-Compatible\" content=\"IE=edge\">\n    <meta name=\"viewport\" content=\"width=device-width, initial-scale=1\">\n\n    <title>uibuilder simple example</title>\n    <meta name=\"description\" content=\"Node-RED uibuilder - Simple example using VueJS\">\n\n    <link rel=\"icon\" href=\"./images/node-blue.ico\">\n\n    <!-- Put your own custom styles in here -->\n    <link rel=\"stylesheet\" href=\"./index.css\" media=\"all\">\n\n</head><body>\n    <!-- The \"app\" element is where the code for dynamic updates is attached -->\n\t<div id=\"app\">\n\t    <h1>A simple uibuilder page</h1>\n\t    <p>\n\t        The elements below are dynamically updated when you send\n\t        a msg to your uibuilder node.\n\t    </p>\n\t    \n\t    <div v-if=\"msg.payload\">\n\t        <h2>Quote of the Day</h2>\n\t        <blockquote>\n\t            <i>{{ msg.payload.quote.body }}</i>\n    \t        <div>{{ msg.payload.quote.author }}</div>\n\t        </blockquote>\n\t    </div>\n\t    \n\t    <h2>The full msg object</h2>\n\t\t<code>{{ msg }}</code>\n\t\t\n\t</div>\n\n    <!-- Vendor Libraries - Load in the right order -->\n    <script src=\"../uibuilder/vendor/socket.io/socket.io.js\"></script>\n    <script src=\"../uibuilder/vendor/vue/dist/vue.min.js\"></script>\n\n    <!-- REQUIRED: Sets up Socket listeners, the uibuilder and msg objects -->\n    <script src=\"./uibuilderfe.min.js\"></script>\n\n    <!-- Put your own custom code in here -->\n    <script src=\"./index.js\"></script>\n\n</body></html>","x":640,"y":140,"wires":[],"icon":"node-red/parser-html.svg"},{"id":"8f8bfd94.685e6","type":"comment","z":"4ed47256.7415cc","name":"index.js","info":"/* jshint browser: true, esversion: 5, asi: true */\n/*globals uibuilder, Vue */\n// @ts-nocheck\n/*\n  Copyright (c) 2020 Julian Knight (Totally Information)\n\n  Licensed under the Apache License, Version 2.0 (the \"License\");\n  you may not use this file except in compliance with the License.\n  You may obtain a copy of the License at\n\n  http://www.apache.org/licenses/LICENSE-2.0\n\n  Unless required by applicable law or agreed to in writing, software\n  distributed under the License is distributed on an \"AS IS\" BASIS,\n  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n  See the License for the specific language governing permissions and\n  limitations under the License.\n*/\n'use strict'\n\n/** @see https://github.com/TotallyInformation/node-red-contrib-uibuilder/wiki/Front-End-Library---available-properties-and-methods */\n\nvar app1 = new Vue({\n    // The HTML element to attach to\n\tel: '#app',\n\t/** Pre-defined data\n\t *  Anything defined here can be used in the HTML\n\t *  if you update it, the HTML will automatically update\n\t */\n\tdata: {\n\t\tmsg: '[Nothing Recieved Yet]',\n\t},\n\n    // Called after the Vue app has been created. A good place to put startup code\n    created: function() {\n        // **REQUIRED** Start uibuilder comms with Node-RED\n        uibuilder.start()\n    },\n\n    // Called when Vue is fully loaded\n\tmounted: function() {\n\t\t// Keep a convenient reference to the Vue app\n\t\tvar vueApp = this\n\n        /** Triggered when the node on the Node-RED server\n         *  recieves a (non-control) msg\n         */\n\t\tuibuilder.onChange('msg', function(msg) {\n\t\t\tvueApp.msg = msg\n\t\t})\n\n\t\t// Send message back to node-red\n\t\t// uibuilder.send({payload:'some message'})\n\t},\n\t\n}) // --- End of the Vue app definition --- //\n\n// EOF","x":770,"y":140,"wires":[],"icon":"font-awesome/fa-code"},{"id":"8a35b840.a3b2d8","type":"comment","z":"4ed47256.7415cc","name":"index.css","info":"body {font-family: sans-serif; font-size: 120%;}\ndiv, p, code { margin:0.3em; padding: 0.3em;}\n\nblockquote i {\n    font-size: 1.5em; color:grey; font-style: italic;\n}","x":900,"y":140,"wires":[],"icon":"node-red/hash.svg"},{"id":"2cf3f051.3dd33","type":"debug","z":"4ed47256.7415cc","name":"simple-debug","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":960,"y":180,"wires":[]},{"id":"eb95241.bca25d8","type":"uibuilder","z":"4ed47256.7415cc","name":"Simple Example","topic":"","url":"CO2_Girona","fwdInMessages":false,"allowScripts":false,"allowStyles":false,"copyIndex":true,"showfolder":false,"useSecurity":false,"sessionLength":"","tokenAutoExtend":false,"x":750,"y":200,"wires":[["2cf3f051.3dd33"],["4e7c2860.c5c318"]]},{"id":"4e7c2860.c5c318","type":"debug","z":"4ed47256.7415cc","name":"uib controls","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":950,"y":220,"wires":[]},{"id":"16169222.b4d91e","type":"debug","z":"4ed47256.7415cc","name":"qod-debug","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":750,"y":260,"wires":[]},{"id":"fdca4ad5.4ac758","type":"inject","z":"4ed47256.7415cc","name":"Randoms 4s","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"4","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":200,"y":460,"wires":[["d3e54dbc.58ca4"]]},{"id":"d3e54dbc.58ca4","type":"function","z":"4ed47256.7415cc","name":"","func":"var CO2,temp,humitat;\nCO2=parseInt(Math.random() * (2000-500)+500,10);\ntemp=parseFloat((Math.random() * (40-16)+16).toFixed(2));\nhumitat=parseFloat((Math.random() * (100-0)).toFixed(2));\n\nglobal.set(\"CO2\",CO2);\nglobal.set(\"temp\",temp);\nglobal.set(\"humitat\",humitat);\n\nmsg.CO2=CO2;\nmsg.temp=temp;\nmsg.humitat=humitat;\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":440,"y":460,"wires":[["6d2a1c66.42cab4"]]},{"id":"6d2a1c66.42cab4","type":"debug","z":"4ed47256.7415cc","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":630,"y":460,"wires":[]},{"id":"6afd0758.f17f58","type":"inject","z":"4ed47256.7415cc","name":"Actualitzar web","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"4","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":220,"y":200,"wires":[["7621b519.b1f18c"]]},{"id":"7621b519.b1f18c","type":"function","z":"4ed47256.7415cc","name":"","func":"var CO2, humitat, temp, rand;\n\nCO2=global.get(\"CO2\")||0;\nhumitat=global.get(\"humitat\")||0;\ntemp=global.get(\"temp\")||0;\nrand=parseFloat((Math.random() * (100-0)).toFixed(2));\n\nmsg.CO2=CO2;\nmsg.humitat=humitat;\nmsg.temp=temp;\nmsg.rand=rand;\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":420,"y":200,"wires":[["eb95241.bca25d8","16169222.b4d91e","a28fd1d.008763"]]},{"id":"a28fd1d.008763","type":"debug","z":"4ed47256.7415cc","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":760,"y":320,"wires":[]}]

If I try to add the Apex bar Chart, all data running now, breaks down.
Someone can help me in this part?

Thanks in advance.

Pau

What you have shared doesn't really help since you've not shared your front-end code.

Please share the front-end code and some example data rather than making us load a complete flow that makes changes to the global vars.

Hi @TotallyInformation , sorry for my late reply.

See attached front-end code.
I'm newbie in uibuilder and Vue/Bootstrap.

index.html

<!doctype html><html lang="ca"><head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="Chromium">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>CO2 Monitor</title>
    <meta name="description" content="CO2 Monitor Elektra Catalunya using VueJS">
    <link rel="icon" href="./images/node-blue.ico">
    <!-- Put your own custom styles in here -->
    <link rel="stylesheet" href="./index.css" media="all">
</head>

<body>
    <!-- The "app" element is where the code for dynamic updates is attached -->
	<div id="app">
        <div>
            <table class="table">
                <tr>
                <th>
                    <div class="dadesNR" v-if="msg.CO2">
	                <h1>INTERIOR</h1>
	                <blockquote>
	                <i>{{ msg.CO2 }} PPM</i>
	                </blockquote>
	                </div>
	                <div class="dadesNR" v-if="msg.temp">
	                <h1>EXTERIOR</h1>
	                <blockquote>
	                <i>{{ msg.temp }} PPM</i>
	                </blockquote>
	                </div>
                </th>
                
                <th>
                    <div class="barchart">
	                <h1>Bar Chart</h1>
	                <bar-chart></bar-chart>
	                </div>
                </th>
                <th>
                    <div class="cara" v-if="msg.CO2<1000">
	                <img src="smilegreen.png" />
	                </div>
	                <div class="cara" v-else-if="msg.CO2>1000 && msg.CO2<1500">
	                <img src="yellowface.png" />
	                </div>
	                <div class="cara" v-else-if="msg.CO2>=1500">
	                <img src="angryred.png" />
	                </div>
                </th>
                </tr>
            </table>
        </div>
	  
	    
	    
	    
	    
	    
	  <!-- 
	    <h2>Missatge sencer</h2>
		<code>{{ msg }}</code>
		!-->
	    
	    
	    
	    
		<!--
        <div id="barra">
		    <b-row>
                <b-card col class="w-50" header="Bar Chart" border-variant="primary" header-bg-variant="primary" header-text-variant="white" align="center">
                    <apexchart width="100%" type="bar" :options="options" :series="series"></apexchart>
                </b-card>
            </b-row>
		</div>
		!-->
		
	</div>

    <!-- Vendor Libraries - Load in the right order -->
    <script src="../uibuilder/vendor/socket.io/socket.io.js"></script>
    <script src="../uibuilder/vendor/vue/dist/vue.min.js"></script>
    <script src="../uibuilder/vendor/bootstrap-vue/dist/bootstrap-vue.js"></script>
    <script src="./home/pi/node_modules/chart.js/dist/chart.js"></script>

    <!--
    <script src="../uibuilder/vendor/vue/apexcharts.js"></script>
    <script src="../uibuilder/vendor/vue/vue-apexcharts.js"></script>
    !-->
    
    <!-- REQUIRED: Sets up Socket listeners, the uibuilder and msg objects -->
    <script src="./uibuilderfe.min.js"></script>

    <!-- Put your own custom code in here -->
    <script src="./index.js"></script>

</body></html>

index.css

body {
 font-family: sans-serif;
 color: #40c98d;
 background-color: #000000;
 padding: 5%;
 font-size: 100%;
}

.dadesNR {
  background: #000000;
  width: 900px;
  height: 100%;
  padding: 40px;
  display: inline-block;
  vertical-align: top;
  margin: 10px;
  color: #FFFFFF;
  text-align: center;
}

.barchart{
  background: #000000;
  width: 100px;
  height: 100%;
  padding: 25px;
  display: inline-block;
  vertical-align: top;
  margin: 10px;
  color: #FFFFFF;
  text-align: center;
}

canvas {
	display: block;
	max-width: 600px;
	margin: 60px auto;
}

.cara {
  background: #f9f9f9;
  height: 100%;
  padding: 50px;
  display: inline-block;
  vertical-align: top;
  margin: 10px;
  border-radius: 45px;
  color: #27394a;
  text-align: center;
}

.cara img{
    width: 50px;
}

div, p, code { margin:0px; padding: 0px;}

blockquote i {
    font-size: 80px; color:green; font-style: normal;
}

index.js

/* jshint browser: true, esversion: 5, asi: true */
/*globals uibuilder, Vue */
// @ts-nocheck
/*
  Copyright (c) 2020 Julian Knight (Totally Information)

  Licensed under the Apache License, Version 2.0 (the "License");
  you may not use this file except in compliance with the License.
  You may obtain a copy of the License at

  http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.
*/
'use strict'
/** @see https://github.com/TotallyInformation/node-red-contrib-uibuilder/wiki/Front-End-Library---available-properties-and-methods */
var app1 = new Vue({
    // The HTML element to attach to
	el: '#app',
	/** Pre-defined data
	 *  Anything defined here can be used in the HTML
	 *  if you update it, the HTML will automatically update
	 */
	data: {
		msg: '[No es reben dades]',
	}, // End of data
	
	computed: {
    }, // --- End of computed --- //

    methods: {
    }, // --- End of methods --- //

    

    // Called after the Vue app has been created. A good place to put startup code
    created: function() {
        // **REQUIRED** Start uibuilder comms with Node-RED
        uibuilder.start()
    },

    // Called when Vue is fully loaded
	mounted: function() {
		// Keep a convenient reference to the Vue app
		var vueApp = this

        /** Triggered when the node on the Node-RED server
         *  recieves a (non-control) msg
         */
		uibuilder.onChange('msg', function(msg) {
			vueApp.msg = msg
		})
		
		// Process new messages from Node-RED

        uibuilder.onChange('msg', function (newVal) {
            if ( typeof newVal.payload === 'number' ){
                // Add new element
                vueApp.dseries.push(newVal.payload)
                // Lose the first element
                vueApp.dseries.shift()
                //console.log(vueApp.dseries)
            }
        })

		// Send message back to node-red
		// uibuilder.send({payload:'some message'})
	},
	
}) // --- End of the Vue app definition --- //
// EOF

I would like to add a bar chart like this one, or similar, with msg.CO2 value scaled 0-100%, without scale.

HTML:

<canvas id="bar-chart" width="400" height="300"></canvas>
<!-- <canvas id="line-chart" width="400" height="400"></canvas> -->

CSS:

canvas {
	display: block;
	max-width: 600px;
	margin: 60px auto;
}

JS:

// Chart.defaults.global.elements.rectangle.backgroundColor = '#FF0000';
var bar_ctx = document.getElementById('bar-chart').getContext('2d');
var green_red_gradient = bar_ctx.createLinearGradient(0, 0, 0, 400);
green_red_gradient.addColorStop(0, 'red');
green_red_gradient.addColorStop(1, 'green');
var bar_chart = new Chart(bar_ctx, {
    type: 'bar',
    data: {
        labels: [""],
        datasets: [{
            label: 'ppm',
            data: [100],
						backgroundColor: green_red_gradient,
						hoverBackgroundColor: green_red_gradient,
						hoverBorderWidth: 2,
						hoverBorderColor: 'purple'
        }]
    },
    options: {
        scales: {
            yAxes: [{
                ticks: {
                    beginAtZero:true
                }
            }]
        }
    }
});

Thanks in advance.

Needs an example of your input data.

Hi @TotallyInformation ,

Finally I've solved the issue in other way, using a wrapper with variable height (v-bind) to cover a rectangle (vertical chart bar).
Anyway, I wold like to know wich is the way with AppexChart or other.

See attached input data:
NR UIBuilder input data

PD-> In this case, the bar chart have to display CO2int value.

Thanks
Pau

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