<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

        时间:2023-11-01
          <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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:Chart.js:如何更改任何尺寸的 x 轴刻度标签对齐方式? 下一篇:图表js中饼图之间的填充

                  相关文章

                1. <tfoot id='Lk6IG'></tfoot>

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

                      <bdo id='Lk6IG'></bdo><ul id='Lk6IG'></ul>
                  1. <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>