繁体   English   中英

JavaScript在另一个HTML页面上显示HTML值

[英]JavaScript to display HTML values on another HTML page

接下来的2个div使用本地存储将测试和时间输出到HTML页面上。 这两个值在HTML页面上正常显示。

    <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”值?

在此处输入图片说明

首先创建一个空的dataPoints数组,然后通过localStorage Object进行迭代。创建一个具有Y和测试值的Object并推送到dataPoints数组

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM