ChartJS 隐藏条形图中的网格

g9icjywg  于 2022-12-13  发布在  Chart.js
关注(0)|答案(1)|浏览(182)
import React from 'react';
import {
    Chart as ChartJS,
    CategoryScale,
    LinearScale,
    BarElement,
    Title,
    Tooltip,
    Legend
} from 'chart.js';
import { Bar } from 'react-chartjs-2';

ChartJS.register(
    CategoryScale,
    LinearScale,
    BarElement,
    Title,
    Tooltip,
    Legend,
);


const options = {
    responsive: true,
    elements: {
        bar: {
            borderWidth: 2,
        },
    },
    plugins: {
        scales: {
            x: {
                grid: {
                    display: false
                }
            },
            y: {
                grid: {
                    display: false
                }
            },
        },
        legend: {
            display: false,
        },
        title: {
            display: false,
            // text: 'Top Application Accessed',
        },
    },
};

const labels = ["a", "b", "c", "d0", "d", "e", "t"];
const v = [8, 10, 15, 2, 4, 11, 17]

const data = {
    labels,
    datasets: [
        {
            label: "Total no of errors",
            data: v,
            backgroundColor: 'blue',
        }
    ],
};

export default function App() {
    return <Bar options={options} data={data} />;
}

在上面的代码中,所有的代码都没有任何效果。我想隐藏图表中的网格。
我还想添加一些功能到我的图表,但任何我添加到这个代码没有影响的结果。
而不是完整的网格,我希望虚线网格只平行于x轴。我还想添加不同的颜色,所有的酒吧。

fcipmucu

fcipmucu1#

你已经把你的比例条件放在选项对象的插件部分。这是不正确的,你需要把比例部分放在选项对象的根。这样它就可以正常工作了。
因此,您将得到的不是options.plugins.scales.xoptions.plugins.scales.yoptions.scales.xoptions.scales.y

相关问题