Explorar el Código

上傳檔案到 'static'

miacheng913 hace 3 años
padre
commit
8eb9151a5b
Se han modificado 1 ficheros con 56 adiciones y 1 borrados
  1. 56 1
      static/tower.js

+ 56 - 1
static/tower.js

@@ -347,4 +347,59 @@ function tower_perform_show(obj_tmp){
 
     document.getElementById('tower_perfrom').innerHTML=inner;
 
-}
+}
+
+get_predict();
+function get_predict(){
+    var xhr = new XMLHttpRequest();
+    var url = "channel_predict/dev001/ch01";
+    obj3="";
+
+    xhr.open("GET",url);
+    xhr.onload = function(){
+        obj3 = JSON.parse(xhr.responseText);
+        labels = new Array();
+        for(var i=0;i<obj3.data.length;i++){
+            labels.push(i);
+        }
+        console.log(obj3)
+        var Data = {
+            labels: labels, //顯示區間名稱
+            datasets: [{
+                label: "predict", // tootip 出現的名稱
+                lineTension: 0, // 曲線的彎度,設0 表示直線
+                backgroundColor: "#ea464d",
+                borderColor: "#ea464d",
+                borderWidth: 5,
+                data:obj3.data, // 資料
+                fill: false, // 是否填滿色彩
+            },]
+        };
+        var ctx = document.getElementById("channel_predict").getContext("2d");
+        drawLineCanvas(ctx,Data);
+    };
+    xhr.send();
+}
+function drawLineCanvas(ctx,data) {
+    window.myLine = new Chart(ctx, {  //先建立一個 chart
+        type: 'line', // 型態
+        data: data,
+        options: {
+                responsive: true,
+                legend: { //是否要顯示圖示
+                    display: true,
+                },
+                tooltips: { //是否要顯示 tooltip
+                    enabled: true
+                },
+                scales: {  //是否要顯示 x、y 軸
+                    xAxes: [{
+                        display: true
+                    }],
+                    yAxes: [{
+                        display: true
+                    }]
+                },
+            }
+    });
+};