Differences

This shows you the differences between two versions of the page.

Link to this comparison view

jsapi:a_simple_example [2025/04/30 02:58] (current)
optrix created
Line 1: Line 1:
 +====A Simple Live-Data Web Page====
  
 +Below you'll find the code for a simple web-page that displays the current speed of the Paint Line on our demo server.
 +
 +<code html>
 +<html>
 +  <head>
 +    <title>Testing</title>
 +    <script src="https://demo.optrix.com.au/plugins/optrix/hmitt.js"></script>
 +  </head>
 +  <body>
 +    <div id="display">
 +       Unknown
 +    </div>
 +
 +    <script>
 +
 +//Create a connection
 +var connection = new HMITTPanel();
 +
 +//Subscribe to points
 +connection.Sub("Paint Line.Speed - Actual",function (v) {
 +   document.querySelector('#display').innerHTML = parseFloat(v).toFixed(2) + " m/min";
 +});
 +
 +//Connect to the server
 +connection.UseSSL();
 +connection.Connect("demo.optrix.com.au/s/pl");
 +
 +    </script>
 +
 +  </body>
 +</html>
 +</code>
 +
 +===Smoothness===
 +
 +If you opened the HTML above, you'll notice that the data is **animated**. The library automatically smooths the transition between data updates by interpolating the incoming values over time.
 +
 +While this works beautifully in some cases, there are types of data and visualisation that it isn't very useful for.
 +
 +An optional 3rd parameter to 'Sub' allows you to prevent animation.
 +
 +<code>
 +connection.Sub("Paint Line.Speed - Actual",function (v) {
 +   document.querySelector('#display').innerHTML = parseFloat(v).toFixed(2) + " m/min";
 +},true);
 +</code>
 +
 +===More Complex Examples===
 +
 +This all works well if you only ever want to work with one data point at a time, but what happens when you want to compare point values, or perform analysis?
 +
 +[[Introducing GetValue|Discover the GetValue function]]