<tfoot id='fKDAd'></tfoot>

<small id='fKDAd'></small><noframes id='fKDAd'>

    <i id='fKDAd'><tr id='fKDAd'><dt id='fKDAd'><q id='fKDAd'><span id='fKDAd'><b id='fKDAd'><form id='fKDAd'><ins id='fKDAd'></ins><ul id='fKDAd'></ul><sub id='fKDAd'></sub></form><legend id='fKDAd'></legend><bdo id='fKDAd'><pre id='fKDAd'><center id='fKDAd'></center></pre></bdo></b><th id='fKDAd'></th></span></q></dt></tr></i><div id='fKDAd'><tfoot id='fKDAd'></tfoot><dl id='fKDAd'><fieldset id='fKDAd'></fieldset></dl></div>
      <bdo id='fKDAd'></bdo><ul id='fKDAd'></ul>

    1. <legend id='fKDAd'><style id='fKDAd'><dir id='fKDAd'><q id='fKDAd'></q></dir></style></legend>

      1. 每秒刷新一次图表数据javascript

        refresh chart data every second javascript(每秒刷新一次图表数据javascript)
          <tbody id='wVlOY'></tbody>
            <bdo id='wVlOY'></bdo><ul id='wVlOY'></ul>

            <small id='wVlOY'></small><noframes id='wVlOY'>

            <legend id='wVlOY'><style id='wVlOY'><dir id='wVlOY'><q id='wVlOY'></q></dir></style></legend>
              <tfoot id='wVlOY'></tfoot>

              • <i id='wVlOY'><tr id='wVlOY'><dt id='wVlOY'><q id='wVlOY'><span id='wVlOY'><b id='wVlOY'><form id='wVlOY'><ins id='wVlOY'></ins><ul id='wVlOY'></ul><sub id='wVlOY'></sub></form><legend id='wVlOY'></legend><bdo id='wVlOY'><pre id='wVlOY'><center id='wVlOY'></center></pre></bdo></b><th id='wVlOY'></th></span></q></dt></tr></i><div id='wVlOY'><tfoot id='wVlOY'></tfoot><dl id='wVlOY'><fieldset id='wVlOY'></fieldset></dl></div>
                  本文介绍了每秒刷新一次图表数据javascript的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我正在创建一个带有图表的 html 网页,该图表显示电压水平不断变化.我想每秒刷新一次页面,以便条形图中的条形变为新值.我不确定如何像这样更新图表数据.到目前为止,我有以下内容:

                  I am creating an html web page with a chart on that shows voltage levels continuously changing. I want to refresh the page every second so that the bars in the bar chart go to the new values. I am not sure how to update the chart data like this. I have the following so far:

                  Chart.plugins.unregister(ChartDataLabels);
                  
                  function myFunction() {
                    var cells = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16];
                    var voltages = [];
                    for (i = 0; i < 16; i++) {
                      voltages[i] = Math.floor(28 + Math.floor(Math.random() * 8)) / 10;
                    }
                  
                    var colours = [];
                    for (i = 0; i < voltages.length; i++) {
                      colours[i] = getColour(voltages[i]);
                    }
                  
                    var ctx = document.getElementById("voltageChart");
                    var voltageChart = new Chart(ctx, {
                      plugins: [ChartDataLabels],
                      type: "bar",
                      data: {
                        labels: cells,
                        datasets: [{
                          data: voltages,
                          backgroundColor: colours,
                        }]
                      },
                    });
                  
                    function updateData(chart) {
                      chart.data.datasets[0].data = voltages;
                      chart.data.datasets[0].backgroundColor = colours;
                      chart.update();
                    }
                  
                    function refreshData() {
                      for (i = 0; i < 16; i++) {
                        voltages[i] = Math.floor(28 + Math.floor(Math.random() * 8)) / 10;
                      }
                  
                      for (i = 0; i < voltages.length; i++) {
                        colours[i] = getColour(voltages[i]);
                      }
                  
                      updateData(voltageChart);
                    }
                  
                    setInterval(refreshData, 1500);
                  }
                  

                  推荐答案

                  我们可以使用 chart.data.datasets.pop() 推送新数据 chart.data.datasets.push() 然后调用 chart.js 函数 chart.update 重新渲染图形.这是示例:https://codepen.io/bhupendra1011/pen/MWwWogO?editors=1111.

                  We can use chart.data.datasets.pop() and push new data chart.data.datasets.push() and then invoke chart.js function chart.update to re-render the graph . here is the example : https://codepen.io/bhupendra1011/pen/MWwWogO?editors=1111.

                  更多关于添加/删除数据这里

                  More on adding/removing data here

                  这篇关于每秒刷新一次图表数据javascript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  在开发JS过程中,会经常遇到两个小数相运算的情况,但是运算结果却与预期不同,调试一下发现计算结果竟然有那么长一串尾巴。如下图所示: 产生原因: JavaScript对小数运算会先转成二进制,运算完毕再转回十进制,过程中会有丢失,不过不是所有的小数间运算会
                  问题描述: 在javascript中引用js代码,然后导致反斜杠丢失,发现字符串中的所有\信息丢失。比如在js中引用input type=text onkeyup=value=value.replace(/[^\d]/g,) ,结果导致正则表达式中的\丢失。 问题原因: 该字符串含有\,javascript对字符串进行了转
                  Rails/Javascript: How to inject rails variables into (very) simple javascript(Rails/Javascript:如何将 rails 变量注入(非常)简单的 javascript)
                  quot;Each child in an array should have a unique key propquot; only on first time render of page(“数组中的每个孩子都应该有一个唯一的 key prop仅在第一次呈现页面时)
                  CoffeeScript always returns in anonymous function(CoffeeScript 总是以匿名函数返回)
                  Ordinals in words javascript(javascript中的序数)

                  • <tfoot id='Lk6IG'></tfoot>

                      <small id='Lk6IG'></small><noframes id='Lk6IG'>

                        <bdo id='Lk6IG'></bdo><ul id='Lk6IG'></ul>
                      • <legend id='Lk6IG'><style id='Lk6IG'><dir id='Lk6IG'><q id='Lk6IG'></q></dir></style></legend>
                          <i id='Lk6IG'><tr id='Lk6IG'><dt id='Lk6IG'><q id='Lk6IG'><span id='Lk6IG'><b id='Lk6IG'><form id='Lk6IG'><ins id='Lk6IG'></ins><ul id='Lk6IG'></ul><sub id='Lk6IG'></sub></form><legend id='Lk6IG'></legend><bdo id='Lk6IG'><pre id='Lk6IG'><center id='Lk6IG'></center></pre></bdo></b><th id='Lk6IG'></th></span></q></dt></tr></i><div id='Lk6IG'><tfoot id='Lk6IG'></tfoot><dl id='Lk6IG'><fieldset id='Lk6IG'></fieldset></dl></div>

                              <tbody id='Lk6IG'></tbody>