使chartjs图例标签可标签

时间:2019-03-19 19:23:22

标签: chart.js react-chartjs

我正在尝试使图表上的标签具有标签性。 在此实现中,我正在使用react-chartjs-2。 但是,配置选项对象仍然是chartjs的标准。

示例代码:

    const options = {
        legend: {
            onHover: (e) => {
                console.log(e.target); // this is the entire legend, not individual labels
            },
            labels: {
                onHover: (e) => { 
                /* doesn't work; trying to see if have access to e.target even to do DOM manipulation... */
                    console.log(e.target); // doesn't fire
                }
            }
        }
    }

有趣的是,单击这些标签可以过滤该数据集的显示,我只需要一种使回车键既可点击又可点击的方法。

我已经搜索了chartjs文档,但是找不到添加悬停和焦点事件或启用标签的焦点能力的方法(屏幕快照为2014年秋季至2018年秋季)。

enter image description here

1 个答案:

答案 0 :(得分:-1)

我认为只指定位置就可以得到结果。

options: {
    legend: {
        position: 'top'
    },
}
相关问题