<tfoot id='oaOQu'></tfoot>
  • <small id='oaOQu'></small><noframes id='oaOQu'>

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

          <bdo id='oaOQu'></bdo><ul id='oaOQu'></ul>

        Chartjs - 如何在 x 轴标签上获取最后 7 天?

        Chartjs - How to get last 7 days on x-axis labels?(Chartjs - 如何在 x 轴标签上获取最后 7 天?)
        <tfoot id='UuvBR'></tfoot>

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

        • <bdo id='UuvBR'></bdo><ul id='UuvBR'></ul>

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

                  <legend id='UuvBR'><style id='UuvBR'><dir id='UuvBR'><q id='UuvBR'></q></dir></style></legend>
                1. 本文介绍了Chartjs - 如何在 x 轴标签上获取最后 7 天?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我试图在我的折线图的 x 轴上获取最后 7 天(使用 chartjs).最好的方法是什么?

                  I am trying to get the last seven days on the x-axis of my line-chart (using chartjs). What is the best way to do this?

                  谢谢

                  推荐答案

                  您可以使用以下代码实例化过去 7 天的图表:

                  You can instantiate a chart for the last seven days with the following code:

                  let start = new Date(),
                    end = new Date();
                  
                  start.setDate(start.getDate() - 7); // set to 'now' minus 7 days.
                  start.setHours(0, 0, 0, 0); // set to midnight.
                  
                  new Chart(document.getElementById("chart"), {
                    type: "line",
                    options: {
                      scales: {
                        xAxes: [{
                          type: "time",
                          time: {
                            min: start,
                            max: end,
                            unit: "day"
                          }
                        }]
                      }
                    }
                  });

                  <script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.8.0/Chart.bundle.min.js"></script>
                  <canvas id="chart"></canvas>

                  日期算术之所以有效是因为 日期对象在设置月份的值无效时自动更正.

                  The date arithmetic works because of the Date object auto correcting itself when the value is invalid for the set month.

                  您需要将值提供为 x(或 t)&y 属性,指定在文档中.

                  You'll need to provide your values as x (or t) & y properties, as specified in the documentation.

                  这篇关于Chartjs - 如何在 x 轴标签上获取最后 7 天?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                  相关文档推荐

                  在开发JS过程中,会经常遇到两个小数相运算的情况,但是运算结果却与预期不同,调试一下发现计算结果竟然有那么长一串尾巴。如下图所示: 产生原因: JavaScript对小数运算会先转成二进制,运算完毕再转回十进制,过程中会有丢失,不过不是所有的小数间运算会
                  append() 方法在被选元素的结尾(仍然在内部)插入指定内容。 语法: $(selector).append( content ) var creatPrintList = function(data){ var innerHtml = ""; for(var i =0;i data.length;i++){ innerHtml +="li class='contentLi'"; innerHtml +="a href
                  问题描述: 在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)
                  CoffeeScript always returns in anonymous function(CoffeeScript 总是以匿名函数返回)
                  Ordinals in words javascript(javascript中的序数)

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

                      <tbody id='WPVI5'></tbody>

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

                      <legend id='WPVI5'><style id='WPVI5'><dir id='WPVI5'><q id='WPVI5'></q></dir></style></legend>

                          <bdo id='WPVI5'></bdo><ul id='WPVI5'></ul>