Chart.js 2.0(条形图)减少每2 bar之间的x轴距离

时间:2016-08-30 04:09:25

标签: javascript charts bar-chart chart.js2

如标题所述,如何减少chart.js 2.0中条形之间的x轴距离,如下图所示。

Example

目前,这是我的栏目

enter image description here

这是我的代码

.

https://jsfiddle.net/mx2gh59k/

1 个答案:

答案 0 :(得分:-1)

您可以制作多个数据集。一个用于2004年,一个用于2014年。 有一个示例代码:http://www.chartjs.org/docs/

var data = {
labels: ["Eating", "Drinking", "Sleeping", "Designing", "Coding", "Cycling", "Running"],
    datasets: [
        {
            label: "My First dataset",
            backgroundColor: "rgba(179,181,198,0.2)",
            borderColor: "rgba(179,181,198,1)",
            pointBackgroundColor: "rgba(179,181,198,1)",
            pointBorderColor: "#fff",
            pointHoverBackgroundColor: "#fff",
            pointHoverBorderColor: "rgba(179,181,198,1)",
            data: [65, 59, 90, 81, 56, 55, 40]
        },
        {
            label: "My Second dataset",
            backgroundColor: "rgba(255,99,132,0.2)",
            borderColor: "rgba(255,99,132,1)",
            pointBackgroundColor: "rgba(255,99,132,1)",
            pointBorderColor: "#fff",
            pointHoverBackgroundColor: "#fff",
            pointHoverBorderColor: "rgba(255,99,132,1)",
            data: [28, 48, 40, 19, 96, 27, 100]
        }
    ]
};

我已经做了同样的事情,但我现在无法发布截图。