javascript - 如何从图表js中的图表中删除轴线

标签 javascript jquery angularjs charts chart.js

我使用图表js绘制了一个图表,如下所示

enter image description here

在上面的图表中,我想像其他线一样加粗一条线(粉红色标记),并且我想删除 x 轴线(绿色标记)。我该怎么做,请帮助我。

请在这里查看 fiddle Live Chart

    var ganttchart = document.getElementById('bar-chart');
    new Chart(ganttchart, {
            type: 'line',
            data: {
                datasets: [
                {

                    label: 'Scatter Dataset',
                    backgroundColor: "rgba(246,156,85,1)",
                    borderColor: "rgba(246,156,85,1)",
                    fill: false,
                    borderWidth : 15,
                    pointRadius : 0,
                    data: [
                        {
                            x: 0,
                            y: 9
                        }, {
                            x: 3,
                            y: 9
                        }
                    ]
                },
                {
                    backgroundColor: "rgba(208,255,154,1)",
                    borderColor: "rgba(208,255,154,1)",
                    fill: false,
                    borderWidth : 15,
                    pointRadius : 0,
                    data: [
                        {
                            x: 3,
                            y: 7
                        }, {
                            x: 5,
                            y: 7
                        }
                    ]
                },
                {

                    label: 'Scatter Dataset',
                    backgroundColor: "rgba(246,156,85,1)",
                    borderColor: "rgba(246,156,85,1)",
                    fill: false,
                    borderWidth : 15,
                    pointRadius : 0,
                    data: [
                        {
                            x: 5,
                            y: 5
                        }, {
                            x: 10,
                            y: 5
                        }
                    ]
                },
                {
                    backgroundColor: "rgba(208,255,154,1)",
                    borderColor: "rgba(208,255,154,1)",
                    fill: false,
                    borderWidth : 15,
                    pointRadius : 0,
                    data: [
                        {
                            x: 10,
                            y: 3
                        }, {
                            x: 13,
                            y: 3
                        }
                    ]
                }
                ]
            },
            options: {
                legend : {
                    display : false
                },
                scales: {
                    xAxes: [{
                        type: 'linear',
                        position: 'top',
                        gridLines: {
                            lineWidth:20
                        },
                        ticks : {
                            beginAtzero :true,
                            stepSize : 1
                        }
                    }],
                    yAxes : [{

                        gridLines: {
                            display:false,
                        },
                        ticks : {
                            beginAtZero :true,
                            max : 10,
                            display:false
                        }

                    }]
                },
                animation: {
                  duration: 0
                },
                hover: {animationDuration: 0}
            }
        });

最佳答案

您当前可以在此处找到轴配置选项:Axes - Chart.js Documentation

Axes 配置选项有一个全局字段 display ,其描述如下:

如果设置为 false,则轴将在 View 中隐藏。覆盖 gridLines.display、scaleLabel.display 和ticks.display。

这是我的实现方式:

public chartOptions = {
    scales: {
        xAxes: [{
            display: false,
        }],
        yAxes: [{
            display: false,
        }]
    }
};

关于javascript - 如何从图表js中的图表中删除轴线,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41276622/

相关文章:

jquery - 外部内容加载导致 div 无法扩展到页面底部

jquery - 如何将数字转换为逗号分隔的十进制数?

javascript - AngularJs 清理和显示 html

javascript - 指令完全编译/呈现后调用函数

javascript - 将隐藏字段值传递给 javascript (href)

javascript - 在更改文档时选择文本

jQuery.fn.dataTable 未定义

javascript - AngularJS 服务和 promise 最佳实践

javascript - ASP.NET MVC 捆绑子文件夹结构

javascript - 如何缩小jquery文件?