- Create a CSS file with following code:
.Control1.normal{
--ni-indicator-background-color: green;
}
.Control1.warning{
--ni-indicator-background-color: yellow;
}
.Control1.danger{
--ni-indicator-background-color: red;
}
The Control1 refer to the HTML class attribute set for the indicator in G Web.
- Create a JavaScript file with following code:
(function () {
// Use strict prevents silent and common JavaScript errors.
'use strict';
function updateIndicator(value) {
const indicator = document.querySelector('.Control1');
if (value < 50) {
indicator.className = 'Control1 normal';
} else if (value < 80) {
indicator.className = 'Control1 warning';
} else {
indicator.className = 'Control1 danger';
}
}
window.updateIndicator = updateIndicator;
}());
The Control1 refer to the HTML class attribute set for the indicator in G Web.
- Create a G Web project.
- Create a support folder to include the CSS file and JavaScript file.
- Create JavaScript Library Interface and add the function to create entry point for G Web. In the HTML script, add the CSS and JavaScript file path.
- At this moment, your project should looks similar as below:
- Add numeric control as the input for JavaScript function and create numeric indicator as the background color change indicator.
- Now you are done. Execute the webVI and when you change the value or the input argument the indicator should change value. The condition of the color change is based condition set in the JavaScript.