Chart.js ChartJ绘制网格线X轴和Y轴

Chart.js ChartJ绘制网格线X轴和Y轴,chart.js,Chart.js,我第一次尝试chart.js。它具有显示或隐藏垂直或水平网格线的选项,即缩放水平网格线:真/假或缩放垂直网格线:真/假。但它不会在实际的x轴或y轴上绘制网格线。我将如何绘制x轴或y轴的网格线 但它不会在实际的x轴或y轴上绘制网格线 设置缩放水平线或缩放垂直线不会隐藏x轴或y轴 但是,如果确实要在不隐藏比例标签的情况下隐藏(或使其可见),可以这样做 var myChart = new Chart(ctx).Line(data, { scaleLineColor: 'rgba(0, 0

我第一次尝试chart.js。它具有显示或隐藏垂直或水平网格线的选项,即
缩放水平网格线:真/假
缩放垂直网格线:真/假
。但它不会在实际的x轴或y轴上绘制网格线。我将如何绘制x轴或y轴的网格线

但它不会在实际的x轴或y轴上绘制网格线

设置
缩放水平线
缩放垂直线
不会隐藏x轴或y轴


但是,如果确实要在不隐藏比例标签的情况下隐藏(或使其可见),可以这样做

var myChart = new Chart(ctx).Line(data, {
     scaleLineColor: 'rgba(0, 0, 0, 0)',
     ...
隐藏轴。或覆盖任何全局配置并显示轴(可以使用任何颜色)


如果看不到x轴和y轴及其标签,则可能将
showScale
全局配置为false

var myChart = new Chart(ctx).Line(data, {
     showScale: true,
     ...

仅绘制X轴而不绘制Y轴 如果要绘制x轴而不是y轴,则必须同时隐藏x轴和y轴,然后自己绘制x轴,如下所示

Chart.types.Bar.extend({
    name: "BarAlt",
    intialize: function () {
        Chart.types.Bar.intialize.draw.apply(this, arguments);
    },
    draw: function () {
        Chart.types.Bar.prototype.draw.apply(this, arguments);

        var ctx = this.chart.ctx;
        ctx.save();
        ctx.lineWidth = this.scale.lineWidth;
        ctx.strokeStyle = 'white';
        ctx.beginPath();
        ctx.moveTo(this.scale.xScalePaddingLeft, this.scale.calculateY(0));
        ctx.lineTo(this.chart.width, this.scale.calculateY(0));
        ctx.stroke();
        ctx.closePath();
        ctx.restore();
    }
});


var data = {
    labels: ["January", "February", "March", "April", "May", "June", "July"],
    datasets: [
        {
            label: "My First dataset",
            fillColor: "rgba(254, 164, 0, 1)",
            strokeColor: "rgba(254, 164, 0, 1)",
            highlightFill: "rgba(254, 164, 0, 1)",
            highlightStroke: "rgba(254, 164, 0, 1)",
            data: [65, 59, 80, 81, 56, 55, 40]
        }
    ]
};

var ctx = document.getElementById("myChart").getContext("2d");
var myChart = new Chart(ctx).BarAlt(data, {
    scaleFontColor: '#fff',
    scaleGridLineColor: 'rgba(255, 255, 255, 0.4)',
    scaleLineColor: 'rgba(0, 0, 0, 0)',
    scaleShowVerticalLines: false
});

谢谢你友好的回答。我知道你可以显示比例线,但我指的是网格线。我想在我的帖子上显示我的图表(通过添加我想要的图片进行编辑)
Chart.types.Bar.extend({
    name: "BarAlt",
    intialize: function () {
        Chart.types.Bar.intialize.draw.apply(this, arguments);
    },
    draw: function () {
        Chart.types.Bar.prototype.draw.apply(this, arguments);

        var ctx = this.chart.ctx;
        ctx.save();
        ctx.lineWidth = this.scale.lineWidth;
        ctx.strokeStyle = 'white';
        ctx.beginPath();
        ctx.moveTo(this.scale.xScalePaddingLeft, this.scale.calculateY(0));
        ctx.lineTo(this.chart.width, this.scale.calculateY(0));
        ctx.stroke();
        ctx.closePath();
        ctx.restore();
    }
});


var data = {
    labels: ["January", "February", "March", "April", "May", "June", "July"],
    datasets: [
        {
            label: "My First dataset",
            fillColor: "rgba(254, 164, 0, 1)",
            strokeColor: "rgba(254, 164, 0, 1)",
            highlightFill: "rgba(254, 164, 0, 1)",
            highlightStroke: "rgba(254, 164, 0, 1)",
            data: [65, 59, 80, 81, 56, 55, 40]
        }
    ]
};

var ctx = document.getElementById("myChart").getContext("2d");
var myChart = new Chart(ctx).BarAlt(data, {
    scaleFontColor: '#fff',
    scaleGridLineColor: 'rgba(255, 255, 255, 0.4)',
    scaleLineColor: 'rgba(0, 0, 0, 0)',
    scaleShowVerticalLines: false
});