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

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

      <tfoot id='O88HD'></tfoot>

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

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

        chartjs 时间笛卡尔轴适配器和日期库设置

        chartjs time cartesian axis adapter and date library setup(chartjs 时间笛卡尔轴适配器和日期库设置)
        1. <i id='wfJ6n'><tr id='wfJ6n'><dt id='wfJ6n'><q id='wfJ6n'><span id='wfJ6n'><b id='wfJ6n'><form id='wfJ6n'><ins id='wfJ6n'></ins><ul id='wfJ6n'></ul><sub id='wfJ6n'></sub></form><legend id='wfJ6n'></legend><bdo id='wfJ6n'><pre id='wfJ6n'><center id='wfJ6n'></center></pre></bdo></b><th id='wfJ6n'></th></span></q></dt></tr></i><div id='wfJ6n'><tfoot id='wfJ6n'></tfoot><dl id='wfJ6n'><fieldset id='wfJ6n'></fieldset></dl></div>
            <tbody id='wfJ6n'></tbody>
        2. <legend id='wfJ6n'><style id='wfJ6n'><dir id='wfJ6n'><q id='wfJ6n'></q></dir></style></legend>
            • <bdo id='wfJ6n'></bdo><ul id='wfJ6n'></ul>

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

                  <tfoot id='wfJ6n'></tfoot>
                  本文介绍了chartjs 时间笛卡尔轴适配器和日期库设置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我正在尝试实施本教程,但无法完成.https://www.chartjs.org/docs/latest/axes/笛卡尔/time.html

                  I am trying to implement this tutorial and could not get it done. https://www.chartjs.org/docs/latest/axes/cartesian/time.html

                  输入:具有(时间,值)属性的对象列表.Time 是 Integer,表示 unix 时间以秒为单位;值为浮点数.

                  Input: list of objects with (time,value) attributes. Time is Integer that means unix time in seconds; value is Float.

                  教程说日期适配器.时间刻度需要同时存在日期库相应的适配器.请从可用的适配器中选择".

                  The tutorial says "Date Adapters. The time scale requires both a date library and a corresponding adapter to be present. Please choose from the available adapters".

                  日期库,date-fns:https://github.com/date-fns/date-fns

                  问题 1. 如何安装/包含 date-fns 库?文档说npm",但我认为它仅适用于 Node.js,但我有一个 Django 项目,Ubuntu.如果我只是下载 zip,里面有一堆文件.

                  Question 1. how to install/include the date-fns library? The documentation says "npm", but I think it is only for Node.js, but I have a Django project, Ubuntu. If I just download the zip, there is a bunch of files inside.

                  适配器,chartjs-adapter-date-fns https://github.com/chartjs/chartjs-adapter-date-fns.

                  问题2.如何安装fns适配器?文档说npm",但我有一个 Django 项目,Ubuntu.但是,如果我包含 <script src="https://cdn.jsdelivr.net/npm/chartjs-adapter-date-fns/dist/chartjs-adapter-date-fns.bundle.min.js"></script>,我觉得够了.

                  Question 2. how to install the fns adapter? The documentation says "npm", but I have a Django project, Ubuntu. BUT, if I include <script src="https://cdn.jsdelivr.net/npm/chartjs-adapter-date-fns/dist/chartjs-adapter-date-fns.bundle.min.js"></script>, I feel it is enough.

                  问题3.安装适配器和日期库后,如何修复下面的脚本以使情节正常(时间笛卡尔轴)?我认为这都是关于更新行 point["x"] = elem.time; 以将 unix 时间转换为某种适当的类型.

                  Question 3. after installing adapter and date library, how to fix the script below to make the plot work (Time Cartesian Axis)? I think it is all about updating line point["x"] = elem.time; to convert a unix time to some appropriate type.

                  HTML

                  <canvas id="myChart"></canvas>
                  

                  JS

                     let points = [];
                      for(let elem of objs) {
                          point = {};
                          point["x"] = elem.time;
                          point["y"] = elem.value;
                          points.push(point);
                      }
                  
                      var ctx = document.getElementById('myChart').getContext('2d');
                      var chart = new Chart(ctx, {
                          // The type of chart we want to create
                          type: 'line',
                  
                          // The data for our dataset
                          data: points,
                  
                          // Configuration options go here
                          options: {
                              responsive: false,
                  
                              scales: {
                              x: {
                                  type: 'time',
                              }
                          }
                          }
                      });
                  

                  推荐答案

                  确实可以使用脚本标签来安装所有 3 个必需的库,请参阅下面的示例.

                  Installing all the 3 required libs can indeed be done using script tags, see live example underneath.

                  您的数据未显示的原因是因为 chart.js 不希望数据字段中有数据数组.在数据字段中,它需要一个对象,该对象至少具有所有 datasets 的键,该键是一个数组和一个可选的标签数组,但是由于您对数据使用对象格式,因此不需要标签数组.

                  The reason your data doesnt show is because chart.js doesnt expect a data array in the data field. In the data field it expects an object with at least a key for all the datasets which is an array and an optional labels array, but since you are using object format for your data the labels array is not neccesarry.

                  每个数据集都有自己的图例标签,在数据集对象中,您可以在数据字段中配置数据数组.查看实时示例:

                  Each dataset has its own label for the legend and in the dataset object you configure the data array in the data field. See live example:

                  const options = {
                    type: 'line',
                    data: {
                      datasets: [{
                        label: '# of Votes',
                        data: [{
                          x: 1632664468243,
                          y: 5
                        }, {
                          x: 1632664458143,
                          y: 10
                        }],
                        borderColor: 'pink'
                      }]
                    },
                    options: {
                      scales: {
                        x: {
                          type: 'time'
                        }
                      }
                    }
                  }
                  
                  const ctx = document.getElementById('tt').getContext('2d');
                  new Chart(ctx, options);

                  <canvas id="tt"></canvas>
                  <script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/3.5.1/chart.js"></script>
                  <script src="https://cdnjs.cloudflare.com/ajax/libs/date-fns/1.30.1/date_fns.js"></script>
                  <script src="https://cdn.jsdelivr.net/npm/chartjs-adapter-date-fns/dist/chartjs-adapter-date-fns.bundle.min.js"></script>

                  这篇关于chartjs 时间笛卡尔轴适配器和日期库设置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                  相关文档推荐

                  在开发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中的序数)

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

                        <tbody id='qclE6'></tbody>
                        • <bdo id='qclE6'></bdo><ul id='qclE6'></ul>

                        • <tfoot id='qclE6'></tfoot>
                          <legend id='qclE6'><style id='qclE6'><dir id='qclE6'><q id='qclE6'></q></dir></style></legend>