【问题标题】:Chart.js not showing/skipping labelsChart.js 不显示/跳过标签
【发布时间】:2021-05-24 08:36:56
【问题描述】:

我目前正在处理仪表板,并试图在很多人中显示分数。

这是我的 chart.js 代码。

<script>
                            const labels = [
                                @foreach($all_staff as $staff)
                                    @php
                                    $i++;
                                    @endphp
                                '{{ $i }}',
                                @endforeach
                            ];
                            const data = {
                                labels: labels,
                                datasets: [{
                                    label: 'My First dataset',
                                    backgroundColor: 'rgb(255, 99, 132)',
                                    borderColor: 'rgb(255, 99, 132)',
                                    data: [0, 10, 5, 2, 20, 50],
                                }]

                            };
                            // </block:setup>

                            // <block:config:0>
                            const config = {
                                type: 'bar',
                                data,
                                options: {indexAxis: 'y',
                                    scaleShowValues: true,
                                    scales: {
                                        xAxes: [{
                                            ticks: {
                                                beginAtZero: true
                                            }
                                        }],
                                        yAxes: [{
                                            stacked: false,
                                            ticks: {
                                                autoSkip: false,
                                                beginAtZero: true,
                                                stepSize: 1,
                                            }
                                        }]
                                    }
                                }
                            };
                            // </block:config>

                            // === include 'setup' then 'config' above ===

                            var myChart = new Chart(
                                document.getElementById('myChart'),
                                config
                            );
                        </script>

现在就像标题所说的那样,它没有显示所有标签: my chart

所以我从这里尝试了修复:https://github.com/chartjs/Chart.js/issues/2801

遗憾的是,这些都不起作用。

任何帮助都会很棒!谢谢大家!

【问题讨论】:

    标签: javascript php laravel chart.js


    【解决方案1】:

    您的xy 轴配置错误,它们应该是对象而不是数组。

    如果你这样做,它应该可以工作:

    options: {
      scales: {
        x: {
          ticks: {
            beginAtZero: true
          }
        },
        y: {
          ticks: {
            autoSkip: false,
            beginAtZero: true,
            stepSize: 1
          }
        }
      }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-06-29
      • 2019-12-02
      • 1970-01-01
      • 2018-07-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-07-07
      相关资源
      最近更新 更多