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

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

    <tfoot id='xoLWU'></tfoot>

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

      <i id='xoLWU'><tr id='xoLWU'><dt id='xoLWU'><q id='xoLWU'><span id='xoLWU'><b id='xoLWU'><form id='xoLWU'><ins id='xoLWU'></ins><ul id='xoLWU'></ul><sub id='xoLWU'></sub></form><legend id='xoLWU'></legend><bdo id='xoLWU'><pre id='xoLWU'><center id='xoLWU'></center></pre></bdo></b><th id='xoLWU'></th></span></q></dt></tr></i><div id='xoLWU'><tfoot id='xoLWU'></tfoot><dl id='xoLWU'><fieldset id='xoLWU'></fieldset></dl></div>
    2. Chart.js 压缩条形图上的垂直轴

      Chart.js compress vertical axis on barchart(Chart.js 压缩条形图上的垂直轴)
      • <small id='6AOiF'></small><noframes id='6AOiF'>

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

                <bdo id='6AOiF'></bdo><ul id='6AOiF'></ul>
                <tfoot id='6AOiF'></tfoot>
                本文介绍了Chart.js 压缩条形图上的垂直轴的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                我有一个数据集,其中最后一个值总是很高.这导致我的条形图出现问题;如果不将鼠标悬停在它们上面,几乎所有其他值都很难感受.

                I have a dataset in which the last value is always very high. This causes an issue with my bar chart; almost all the other values are hard to get a feeling for without hovering over them.

                这是截图:

                这就是我想要达到的目标;

                This is what I am trying to achieve;

                所以我的问题;这在 vanilla Chart.js 中是否可行,还是我需要一个插件?如果是这样;有现成的插件还是我需要自己写一个?

                So my question; is this possible within vanilla Chart.js or do I need a plugin? And if so; is there an existing plugin or do I need to write one myself?

                我也愿意接受最初问题的替代解决方案.

                I am also open for alternative solutions to the initial problem.

                我已经在整个互联网上寻找类似的东西,但不幸的是没有太多运气.

                I've looked all over the internet for something like this but unfortunately without much luck.

                推荐答案

                可以使用logarithmic type yAxis

                默认:线性

                https://www.chartjs.org/docs/latest/axes/cartesian/logarithmic.html

                var ctx = document.getElementById('myChart');
                
                var myChart = new Chart(ctx, {
                  type: 'bar',
                  data: {
                    labels: ["January", "February", "March", "April", "May", "June"],
                    datasets: [{
                      label: "Series 1",
                      backgroundColor: "rgba(255,99,132,0.2)",
                      borderColor: "rgba(255,99,132,1)",
                      borderWidth: 2,
                      hoverBackgroundColor: "rgba(255,99,132,0.4)",
                      hoverBorderColor: "rgba(255,99,132,1)",
                      data: [65, 59, 43, 81, 56, 950],
                    }]
                  },
                  options: {
                    scales: {
                      yAxes: [{
                        type: 'logarithmic',
                        ticks: {
                          callback: function(tick, index, ticks) {
                            return tick.toLocaleString();
                          }
                        }
                      }]
                    }
                  }
                });

                <script src="https://cdn.jsdelivr.net/npm/chart.js@2.8.0"></script>
                <canvas id="myChart" width="400" height="200"></canvas>

                优化的报价

                50 * (Math.floor(i / 50)), // lower 50
                50 * (Math.ceil(i / 50)) // higer 50
                

                var ctx = document.getElementById('myChart');
                
                var myChart = new Chart(ctx, {
                  type: 'bar',
                  data: {
                    labels: ["January", "February", "March", "April", "May", "June"],
                    datasets: [{
                      label: "Series 1",
                      backgroundColor: "rgba(255,99,132,0.2)",
                      borderColor: "rgba(255,99,132,1)",
                      borderWidth: 2,
                      hoverBackgroundColor: "rgba(255,99,132,0.4)",
                      hoverBorderColor: "rgba(255,99,132,1)",
                      data: [65, 59, 43, 81, 56, 950],
                    }]
                  },
                  options: {
                    scales: {
                      yAxes: [{
                        type: 'logarithmic',
                        ticks: {
                          callback: function(tick, index, ticks) {
                            return tick.toLocaleString();
                          }
                        },
                        afterBuildTicks: function(pckBarChart) {
                          pckBarChart.ticks = pckBarChart.chart.data.datasets[0].data.flatMap(i => [
                            50 * (Math.floor(i / 50)), // lower 50
                            50 * (Math.ceil(i / 50)) // higer 50
                          ])
                        }
                      }]
                    }
                  }
                });

                <script src="https://cdn.jsdelivr.net/npm/chart.js@2.8.0"></script>
                <canvas id="myChart" width="400" height="200"></canvas>

                这篇关于Chart.js 压缩条形图上的垂直轴的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                相关文档推荐

                ChartJS Version 3 - common legend for multiple line charts(ChartJS 版本 3 - 多个折线图的常用图例)
                Charts.js scales yaxes ticks min max doesnt work(Charts.js 缩放 yaxes 刻度 min max 不起作用)
                How to expand the slice of donut chart in chartjs?(如何在chartjs中扩展圆环图的切片?)
                Chart.js yAxes Ticks stepSize not working (fiddle)(Chart.js yAxes Ticks stepSize 不起作用(小提琴))
                Rounded corners on chartJS v.2 - bar charts (with negative values)(chartJS v.2 上的圆角 - 条形图(带负值))
                How to hide value in Chart JS bar(如何在 Chart JS 栏中隐藏值)

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

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

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

                    1. <small id='auaGG'></small><noframes id='auaGG'>