【问题标题】:How to reduce width of dataset in group bar chart which used chartjs如何减少使用chartjs的组条形图中数据集的宽度
【发布时间】:2018-09-10 05:46:25
【问题描述】:

如何在使用 chartjs 的分组条形图中减小数据集的宽度。 在屏幕截图中,我用红线显示了需要减小的宽度。 如果我们可以使用 chartjs 本身来做到这一点会更好,如果不是其他替代方案也欢迎。 我参考这个库http://www.chartjs.org/docs/latest/charts/bar.html

Red line shows which width I need to reduce

【问题讨论】:

  • 你都试过什么?有什么错误吗?

标签: javascript jquery html css chartjs-2.6.0


【解决方案1】:

存储在x轴的那个属性,你只需要像下面这样配置x轴

var options = {
    scales: {
        xAxes: [{
            categoryPercentage: 1.5
        }]
    }
}

var data = {
    labels: ["January", "February", "March", "April", "May", "June", "July"],
    datasets: [{
        label: "Sample Dataset",
        backgroundColor: "rgba(255,0,0,0.4)",
        borderColor: "rgba(75,192,192,1)",
        data: [65, 59, 75, 81, 56, 55, 40],
    }]
};

var ctx = document.getElementById("barChart");
var barChart = new Chart(ctx, {
    type: 'bar',
    data: data,
    options: {
        scales: {
            xAxes: [{
                // Change here
                barPercentage: .5,
            	  categoryPercentage: 1.5
            }]
        }
    }
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.7.2/Chart.min.js"></script>
<canvas id="barChart"></canvas>

【讨论】:

    猜你喜欢
    • 2018-02-05
    • 2018-10-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-08-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多