首页 > 解决方案 > 删除图例 ChartsJS 2.8.0

问题描述

对不起我的英语不好。我是巴西人。我需要删除 chartJS 2.8.0 上的条形图图例。

这是我的代码:

        <div style="height:250px; width:520px;">
            <canvas id="myChartBar"></canvas>
        </div>
        <script type="text/javascript">
            var ctx = document.getElementById('myChartBar');
            var myChart = new Chart(ctx, {
                type: 'bar',
                data: {
                    labels: ['<?php echo implode("','", $resultadoSaldo["label"]) ?>'],
                    datasets: [{
                        label: '# of Votes',
                        data: [<?php echo implode(',', $resultadoSaldo['value'])?>],
                        backgroundColor: ['<?php echo implode("','", $resultadoSaldo["color"]) ?>'],
                        borderColor: ['<?php echo implode("','", $resultadoSaldo["color"]) ?>'],
                        borderWidth: 3
                    }]
                },
                options: {
                    responsive: true,
                    legend: {
                        display: false
                    },
                    scales: {
                        yAxes: [{
                            ticks: {
                                beginAtZero: true
                            }
                        }]
                    }
                }
            });
        </script> 

我认为代码会起作用:图例:{显示:假},

但我的 grafh 也是如此:

在此处输入图像描述

我需要删除这个:

在此处输入图像描述

标签: javascriptchart.js

解决方案


Those labels aren't the legend, they are the X Axis labels. Try this:

options: {
    scales: {
        xAxes: [{
            ticks: {
                display: false
            }
        }]
    }
}

推荐阅读