Advertisement
Shell_Casing

plot

Dec 17th, 2018
749
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. let API = {
  2.     access_token: "eyJhbGcZG1pbiIplm3xpwmmzg",
  3.     url: "https://historian-server:4433/api/v1/forward?url=/historian-rest-api/v1/datapoints/calculated/WIN-9DBOGP80695.Simulation00052/2018-10-02T11:30:00.111Z/2018-10-09T11:30:11.111Z/1/10/5000"
  4. };
  5.  
  6.  
  7. let valuesArray = [];
  8. let timeArray = [];
  9. let samplesSource = 'WIN-9DBOGP80695.Simulation00052';
  10. let chartType = {
  11.     bar: 'bar',
  12.     line: 'line'
  13. };
  14.  
  15. const option = {
  16.     title: {
  17.         text: samplesSource
  18.     },
  19.     tooltip: {},
  20.     legend: {
  21.         data:[]
  22.     },
  23.     xAxis: {
  24.         data: timeArray,
  25.         // category: 'time'
  26.     },
  27.     yAxis: {},
  28.     series: [{
  29.         name: samplesSource,
  30.         type: chartType.bar,
  31.         data: valuesArray
  32.     }]
  33. };
  34.  
  35. async function getValues() {
  36.     try {
  37.         console.log('button clicked');
  38.  
  39.         let xhr = new XMLHttpRequest();
  40.         xhr.open('GET', `${API.url}`, true);
  41.         xhr.setRequestHeader('Authorization', 'Bearer ' + API.access_token);
  42.         // xhr.open('GET', `./data/WIN-9DBOGP80695.Simulation00052 - OG.json`, true);
  43.  
  44.         xhr.onload = async () => {
  45.             if(xhr.status === 200) {
  46.                 // console.log(xhr.responseText);
  47.                 let historianData = await JSON.parse(xhr.responseText);
  48.                 let timeStampsAndValues = historianData.Data[0].Samples;
  49.                 console.log(timeStampsAndValues);
  50.                 timeStampsAndValues.forEach(value => {                    
  51.                     timeArray.push(simplifyTime(value.TimeStamp));
  52.                     // valuesArray.push(Math.ceil(value.Value));
  53.                     valuesArray.push((parseInt(value.Value)).toFixed(0));
  54.                     plotChart();
  55.                 })
  56.  
  57.             }
  58.         };
  59.  
  60.         xhr.send();
  61.  
  62.     } catch (e) {
  63.         console.log(e);
  64.     }
  65. }
  66.  
  67. function simplifyTime(timestamp) {
  68.     return timestamp.slice(0, 19);
  69. }
  70.  
  71. let plot = echarts.init(document.querySelector('#main'));
  72.  
  73. function plotChart() {
  74.     plot.setOption(option);
  75. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement