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

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

      <tfoot id='NR9k4'></tfoot>
      <legend id='NR9k4'><style id='NR9k4'><dir id='NR9k4'><q id='NR9k4'></q></dir></style></legend>
        <bdo id='NR9k4'></bdo><ul id='NR9k4'></ul>

        Charts.js 缩放 yaxes 刻度 min max 不起作用

        Charts.js scales yaxes ticks min max doesnt work(Charts.js 缩放 yaxes 刻度 min max 不起作用)
        • <small id='svWrL'></small><noframes id='svWrL'>

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

                <bdo id='svWrL'></bdo><ul id='svWrL'></ul>
                <tfoot id='svWrL'></tfoot>

                1. 本文介绍了Charts.js 缩放 yaxes 刻度 min max 不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我有一个带有charts.js 图表的HTML 页面.我正在尝试设置图表的最小值和最大值,但我无法设置最小值和最大值.我搜索了不同的帖子,但他们都说同样的话,我很确定我已经这样做了......

                  I have an HTML page with a charts.js chart that works. I'm trying to set the minimum and maximum values of the chart, but I can't set the minimum and maximum values. I searched different posts but they all say the same, and I'm pretty sure I'm already doing that...

                  > scales: {
                  >               yAxes: [{
                  >                 ticks: {
                  >                   min: -100,
                  >                   max: 100
                  >                 }
                  >               }]
                  >             }
                  

                  我就是想不通怎么回事.

                  I just cant figure out what's wrong.

                  <!DOCTYPE html>
                  <html>
                      <head>
                          <script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.9.4/Chart.js"></script>
                          <script src="https://cdn.jsdelivr.net/npm/chart.js@3.0.0/dist/chart.min.js"></script>
                          <script src="https://cdn.jsdelivr.net/npm/chartjs-plugin-datalabels@2.0.0"></script>
                          <script src="https://cdn.jsdelivr.net/npm/chartjs-plugin-datalabels@2.0.0-rc/dist/chartjs-plugin-datalabels.min.js"></script>
                          <title>daily</title>
                      </head>
                      <body>
                      <canvas class='temp_chart' id='temp_chart'>
                      </body>
                  <script>
                  function square_data(chart){
                      var c = document.createElement("canvas");
                      var ctx = c.getContext("2d");
                      ctx.fillStyle = "#FFA500";
                      ctx.rect(145, 70, 15, 15);
                      ctx.fill()
                      ctx.fillStyle = "#fff";
                      ctx.fillText(chart.dataset.data[chart.dataIndex], 147,82, 10);
                  
                      ctx.stroke();
                      return c
                  }
                  const time_of_day = ['Morning', 'Day', 'Evening', 'Night']
                  var temperatures = [15, 18, 4, -6]
                  var ctx = document.getElementById('temp_chart').getContext('2d')
                       window.chart = new Chart(ctx, {
                        type: 'line',
                        data: {
                          labels: time_of_day,
                          datasets: [{
                            fill:false,
                            label: 'Cantidad Estudiantes',
                            data: temperatures,
                            borderColor: [
                              'rgba(0, 0, 0, 1)',
                  
                            ],
                            borderWidth: 3
                          }]
                        },
                        options: {
                          plugins: {
                              legend: {
                              display: false,
                           },
                            datalabels: {
                                anchor: 'start',
                                align: '-45',
                                clamp: true,
                                color: "orange",
                            }
                          },
                          elements:{
                                  "point":{"pointStyle":square_data},
                              }
                      },
                      scales: {
                            yAxes: [{
                              ticks: {
                                min: -100,
                                max: 100
                              }
                            }]
                          }
                        });
                  </script>

                  推荐答案

                  这是因为您使用 v2 语法和 v3,所有更改请阅读 迁移指南,您在选项对象之外定义了比例配置.

                  That is because you are using v2 syntax with v3, for all changes please read the migration guide and you defined the scale config outside of the options object.

                  在 v3 中,所有比例都是一个对象,其中对象的键是比例的 ID

                  In v3 all scales are an object where the key of the object is the ID of the scale

                  还需要注册数据标签插件才能工作,请参阅脚本块中的第一行.

                  Also for the datalabels plugin to work you need to register it, see first line in the script block.

                  最后一件事不包括 2 个主要版本的库,出错的可能性很大

                  Last thing dont include 2 major versions of a lib, high chance of giving errors

                  <!DOCTYPE html>
                  <html>
                  
                  <head>
                    <script src="https://cdn.jsdelivr.net/npm/chart.js@3.0.0/dist/chart.min.js"></script>
                    <script src="https://cdn.jsdelivr.net/npm/chartjs-plugin-datalabels@2.0.0"></script>
                    <title>daily</title>
                  </head>
                  
                  <body>
                    <canvas class='temp_chart' id='temp_chart'>
                    </body>
                    <script>
                      Chart.register(ChartDataLabels); // Added this line
                      
                      function square_data(chart) {
                        var c = document.createElement("canvas");
                        var ctx = c.getContext("2d");
                        ctx.fillStyle = "#FFA500";
                        ctx.rect(145, 70, 15, 15);
                        ctx.fill()
                        ctx.fillStyle = "#fff";
                        ctx.fillText(chart.dataset.data[chart.dataIndex], 147, 82, 10);
                  
                        ctx.stroke();
                        return c
                      }
                      const time_of_day = ['Morning', 'Day', 'Evening', 'Night']
                      var temperatures = [15, 18, 4, -6]
                      var ctx = document.getElementById('temp_chart').getContext('2d')
                      window.chart = new Chart(ctx, {
                        type: 'line',
                        data: {
                          labels: time_of_day,
                          datasets: [{
                            fill: false,
                            label: 'Cantidad Estudiantes',
                            data: temperatures,
                            borderColor: [
                              'rgba(0, 0, 0, 1)',
                  
                            ],
                            borderWidth: 3
                          }]
                        },
                        options: {
                          // Changed this block
                          scales: {
                            y: {
                              min: -100,
                              max: 100,
                            }
                          },
                          plugins: {
                            legend: {
                              display: false,
                            },
                            datalabels: {
                              anchor: 'start',
                              align: '-45',
                              clamp: true,
                              color: "orange",
                            }
                          },
                          elements: {
                            "point": {
                              "pointStyle": square_data
                            },
                          }
                        },
                      });
                  
                    </script>

                  这篇关于Charts.js 缩放 yaxes 刻度 min max 不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                  相关文档推荐

                  在开发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. <tfoot id='oksdy'></tfoot>
                      <i id='oksdy'><tr id='oksdy'><dt id='oksdy'><q id='oksdy'><span id='oksdy'><b id='oksdy'><form id='oksdy'><ins id='oksdy'></ins><ul id='oksdy'></ul><sub id='oksdy'></sub></form><legend id='oksdy'></legend><bdo id='oksdy'><pre id='oksdy'><center id='oksdy'></center></pre></bdo></b><th id='oksdy'></th></span></q></dt></tr></i><div id='oksdy'><tfoot id='oksdy'></tfoot><dl id='oksdy'><fieldset id='oksdy'></fieldset></dl></div>

                          <tbody id='oksdy'></tbody>
                            <bdo id='oksdy'></bdo><ul id='oksdy'></ul>
                          • <legend id='oksdy'><style id='oksdy'><dir id='oksdy'><q id='oksdy'></q></dir></style></legend>

                          • <small id='oksdy'></small><noframes id='oksdy'>