2016-04-06 106 views
0

下面的2個div使用本地存儲將測試和時間輸出到HTML頁面上。這兩個值在HTML頁面上顯示得很好。在另一個HTML頁面上顯示HTML值的JavaScript

<div id="test"> 
    </div> 
    <div id="time"> 
    </div> 

我怎麼能更改此JavaScript代碼的y值,使得其「測試1 = 0.25」,這將在圖表上顯示,以匹配本地存儲的值。

<!DOCTYPE HTML> 
<html> 

<head> 
    <script type="text/javascript"> 
    window.onload = function() { 
    var chart = new CanvasJS.Chart("chartContainer", 
    { 
     animationEnabled: true, 
     legend: { 
     cursor:"pointer", 
     itemclick : function(e) { 
      if (typeof (e.dataSeries.visible) === "undefined" || e.dataSeries.visible) { 
       e.dataSeries.visible = false; 
      } 
      else { 
       e.dataSeries.visible = true; 
      } 
      chart.render(); 
     } 
     }, 
     axisY: { 
     title: "Time" 
     }, 
     toolTip: { 
     shared: true, 
     content: function(e){ 
      var str = ''; 
      var total = 0 ; 
      var str3; 
      var str2 ; 
      for (var i = 0; i < e.entries.length; i++){ 
      var str1 = "<span style= 'color:"+e.entries[i].dataSeries.color + "'> " + e.entries[i].dataSeries.name + "</span>: <strong>"+ e.entries[i].dataPoint.y + "</strong> <br/>" ; 
      total = e.entries[i].dataPoint.y + total; 
      str = str.concat(str1); 
      } 
      str2 = "<span style = 'color:DodgerBlue; '><strong>"+e.entries[0].dataPoint.label + "</strong></span><br/>"; 
      str3 = "<span style = 'color:Tomato '>Total: </span><strong>" + total + "</strong><br/>"; 

      return (str2.concat(str)).concat(str3); 
     } 

     }, 
     data: [ 
     {   
     type: "bar", 
     showInLegend: true, 
     name: "Black", 
     color: "#000000", 
     dataPoints: [ 
     { y: 0.18, label: "Test"}, 
     { y: 0.12, label: "Test 1"}, 
     { y: 0.59, label: "Test 2"},   
     { y: 1.15, label: "Test 3"},   
     ] 
     }, 
     ] 
    }); 

chart.render(); 
} 
</script> 

     <script type="text/javascript" src="js/canvasjs.min.js"></script> 
     <script type="text/javascript" src="js/chart.js"></script> 

    </head> 

    <body> 
     <div id="bar" class="full-width"> 

      <span>Results</span> 
     </div> 
     <br> 

     <div id="chartContainer" style="height: 300px; width: 100%;"></div> 
    </body> 
</html> 

這個圖表有設置值輸入到它,而我想知道我可以顯示'div'值嗎?

enter image description here

回答

0

首先創建一個空的數據點陣列通過的localStorage對象的迭代創建Y和測試值的對象,並推到數據點陣列

dataPoints =[]; 
for(loop through local storage obj) { 
var coordObj ={}; 
coordObj.Y = value from local storage 
coordObj.label = "test 
dataPoints.push(coordObj); 
} 
+0

我不明白,你能解釋一下嗎?我試圖在圖表上顯示值'time'和'duration'? – userdanhas1994

+0

構造dataPoints對象數組,其中包含鍵和值對的時間和持續時間 – sushma

+0

我假定dataPoints包含Y值 – sushma

相關問題