<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Problem with assigning value using {{myPoint.renderedValue}}]]></title><description><![CDATA[<p dir="auto">Hi，<br />
Could you please give some suggestions about the last two lines of my code? I am trying to use test={{myPoint.renderedValue}} for assigning the current value of the data point to the variable "test" and put the "test" variable into a function as parameter. The desirable effect is that the block's color keeps changing according to the data point value, which is a random numeric point XID=tsp_1 with range (-2000,2000) updating every 2 seconds, but the value could not be rendered succusfully using my code.<br />
Do I have to include some js library? I saw this video but the download link is not available right now.<br />
<a href="https://forum.infiniteautomation.com/topic/1781/build-a-mango-dashboard-tutorial" rel="nofollow ugc">build-a-mango-dashboard-tutorial</a><br />
I have read the Examples and discussions in the forum but still have no idea. I would really appreciate your help.</p>
<p dir="auto">Sincerely,<br />
Blair</p>
<pre><code>&lt;ma-get-point-value point-xid="tsp_1" point="myPoint"&gt;&lt;/ma-get-point-value&gt;
&lt;p&gt;
The point name is "{{myPoint.name}}" and its value is {{myPoint.renderedValue}}.
&lt;/p&gt;

&lt;head lang="en"&gt;
    &lt;meta charset="UTF-8"&gt;
    &lt;style&gt;
        #div1{
            width: 50px;
            height: 100px;
            background: rgb(0,0,0);
            margin: 0 auto;
        }
        
    &lt;/style&gt;
&lt;/head&gt;

&lt;body&gt;
    &lt;div id="div1" &gt;&lt;/div&gt;
&lt;/body&gt;

&lt;script language="javascript"&gt;

//define three functions 
function componentToHex(c) {
    var hex = c.toString(16);
    return hex.length == 1 ? "0" + hex : hex;
}
 
function rgbToHex(r, g, b) {
    return componentToHex(r) + componentToHex(g) + componentToHex(b);
}
// the x below is approx in the range of (-2000,2000)
function displaycolor(x,y) {
    var div = document.getElementById(y);
    var color = 0;
    var r1 = 0;
    var g1 = 0;
    var b1 = 0;
    
    if (x &gt;=1600) {
        r1=255;
        g1=0;
        b1=0;
    } else if(x &gt; 0) {
        r1=255;
        g1=(x-1600)/(-1600)*255;
        b1=0;
    } else if(x == 0) {
        r1=255;
        g1=255;
        b1=0;
    } else if(x &gt; (-1600)) {
        r1=(x+1600)/1600*255;
        g1=255;
        b1=0;
    }else {
        r1=0;
        g1=255;
        b1=0;
    }
    
	var r2 = Math.round(r1);//round it to the neares integer
	var g2 = Math.round(g1);
	var b2 = Math.round(b1);
    color = rgbToHex(r2,g2,b2);//use the funtion
    div.style.background = "#" + color.toString(16);//set the color
}

var test = 1300;//if changed to test={{myPoint.renderedValue}}, fail to work
displaycolor(test,"div1")//else if changed to ({{myPoint.renderedValue}},"div1"), fail to work
&lt;/script&gt;



</code></pre>
]]></description><link>https://forum.mango-os.com/topic/2982/problem-with-assigning-value-using-mypoint-renderedvalue</link><generator>RSS for Node</generator><lastBuildDate>Thu, 11 Jun 2026 22:45:22 GMT</lastBuildDate><atom:link href="https://forum.mango-os.com/topic/2982.rss" rel="self" type="application/rss+xml"/><pubDate>Mon, 02 Oct 2017 13:47:20 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Problem with assigning value using {{myPoint.renderedValue}} on Tue, 03 Oct 2017 15:59:32 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/blair" aria-label="Profile: blair">@<bdi>blair</bdi></a> said in <a href="/post/15718">Problem with assigning value using {{myPoint.renderedValue}}</a>:</p>
<blockquote>
<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/jared-wiltshire" aria-label="Profile: Jared-Wiltshire">@<bdi>Jared-Wiltshire</bdi></a>  Thank you so much for your reply. Currently with my limited background knowledge I can not fully understand this, but I will learn more about AngularJS and see how it goes :-)</p>
</blockquote>
<p dir="auto">Hopefully this gets you on your way. It's a bit of a shift from the old way of doing things for sure.</p>
]]></description><link>https://forum.mango-os.com/post/15721</link><guid isPermaLink="true">https://forum.mango-os.com/post/15721</guid><dc:creator><![CDATA[Jared Wiltshire]]></dc:creator><pubDate>Tue, 03 Oct 2017 15:59:32 GMT</pubDate></item><item><title><![CDATA[Reply to Problem with assigning value using {{myPoint.renderedValue}} on Tue, 03 Oct 2017 08:43:59 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/jared-wiltshire" aria-label="Profile: Jared-Wiltshire">@<bdi>Jared-Wiltshire</bdi></a>  Thank you so much for your reply. Currently with my limited background knowledge I can not fully understand this, but I will learn more about AngularJS and see how it goes :-)</p>
]]></description><link>https://forum.mango-os.com/post/15718</link><guid isPermaLink="true">https://forum.mango-os.com/post/15718</guid><dc:creator><![CDATA[Blair]]></dc:creator><pubDate>Tue, 03 Oct 2017 08:43:59 GMT</pubDate></item><item><title><![CDATA[Reply to Problem with assigning value using {{myPoint.renderedValue}} on Mon, 02 Oct 2017 16:20:24 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/blair" aria-label="Profile: Blair">@<bdi>Blair</bdi></a> The video you linked to is for Mango 2.x, I have edited the topic to make this clear.</p>
<p dir="auto">Since it seems you are trying to use AngularJS, I'm going to assume you are using Mango 3.x and a custom page inside our new UI module.</p>
<p dir="auto">When using AngularJS you should not be using a <code>&lt;script&gt;</code> tag anywhere in your page. You'll see if you check through our examples (please read <a href="https://help.infiniteautomation.com/getting-started/" rel="nofollow ugc">https://help.infiniteautomation.com/getting-started/</a> to see how to enable the examples menu) that we don't do this anywhere. As you have also noticed you cannot use interpolation (<code>{{ expression }}</code>) inside a script, you use <a href="https://docs.angularjs.org/guide/interpolation" rel="nofollow ugc">AngularJS interpolation</a> in your markup only.</p>
<p dir="auto">In short you should be doing something like this, using the <a href="https://docs.angularjs.org/api/ng/directive/ngStyle" rel="nofollow ugc">AngularJS ngStyle directive</a> -</p>
<pre><code>&lt;p ng-style="{'background-color': myPoint.value &gt;=1600 ? 'rgb(255,0,0)' : 'rgb(0,255,0)' }"&gt;
    The point name is "{{myPoint.name}}" and its value is {{myPoint.renderedValue}}.
&lt;/p&gt;
</code></pre>
<p dir="auto">Note the use of <code>.value</code> as opposed to <code>.renderedValue</code>. We want to use the numeric value of the point, the rendered value is a string which may be comprised of a rounded number and a unit suffix.</p>
<p dir="auto">It's pretty messy trying to put all your conditions into a single expression in the markup so I'd suggest a filter inside a <a href="https://help.infiniteautomation.com/getting-started-with-a-user-module/" rel="nofollow ugc">user module</a>. e.g.</p>
<pre><code>define(['angular', 'require'], function(angular, require) {
'use strict';

var userModule = angular.module('userModule', ['maUiApp']);

userModule.filter('toColor', function () {
    return function (x) {
        let r1, g1, b1;
        
        if (x &gt;=1600) {
            r1=255;
            g1=0;
            b1=0;
        } else if(x &gt; 0) {
            r1=255;
            g1=(x-1600)/(-1600)*255;
            b1=0;
        } else if(x === 0) {
            r1=255;
            g1=255;
            b1=0;
        } else if(x &gt; (-1600)) {
            r1=(x+1600)/1600*255;
            g1=255;
            b1=0;
        }else {
            r1=0;
            g1=255;
            b1=0;
        }
        
        r1 = Math.round(r1);
        g1 = Math.round(g1);
        b1 = Math.round(b1);
        
        return `rgb(${r1}, ${g1}, ${b1})`;
    };
});

return userModule;

}); // define
</code></pre>
<p dir="auto">Then use it like this -</p>
<pre><code>&lt;p ng-style="{'background-color': (myPoint.value | toColor)}"&gt;
    The point name is "{{myPoint.name}}" and its value is {{myPoint.renderedValue}}.
&lt;/p&gt;
</code></pre>
]]></description><link>https://forum.mango-os.com/post/15695</link><guid isPermaLink="true">https://forum.mango-os.com/post/15695</guid><dc:creator><![CDATA[Jared Wiltshire]]></dc:creator><pubDate>Mon, 02 Oct 2017 16:20:24 GMT</pubDate></item></channel></rss>