In chart.js, Is it possible to hide x-axis label/text of bar chart if accessing from mobile?

前端 未结 6 1903
日久生厌
日久生厌 2021-01-13 14:06

In chart.js, Is it possible to hide x-axis label/text of bar chart if accessing from mobile ?

\

6条回答
  •  深忆病人
    2021-01-13 14:44

    You can extend the current BarChart and remove the xLabels like this.

    function registerCustomBarChart() {
        Chart.types.Bar.extend({
            name: "customBarChart",
            initialize: function (data) {
                Chart.types.Bar.prototype.initialize.apply(this, arguments);
                var xLabels = this.scale.xLabels
                xLabels.forEach(function (label, i) {
                        xLabels[i] = '';
                })
            }
        });
    }
    

    var myBarChart = new Chart(context).customBarChart(data);

提交回复
热议问题