简体   繁体   English

Chart.Js条形图未在React App中显示Toolip

[英]Chart.Js Bar Chart not showing Toolip in React App

i ran intro some trouble using chart.js in an electron wrapped react app. 我在电子包装的React应用程序中使用chart.js时遇到了一些麻烦。 For some reason the tool tip on the created charts suddenly stopped working (it has already worked just fine). 由于某种原因,创建的图表上的工具提示突然停止工作(它已经可以正常工作)。 The chart seems to be drawn correctly, only the tooltip upon hovering is not working. 该图表似乎正确绘制,只有悬停时的工具提示不起作用。 The following code snippet defines the data of the chart in a react component: 以下代码段在react组件中定义了图表的数据:
Component 零件

 class App extends Component {
  constructor() {
        super();
    this.state = {
    value: 'Click to Upload File',
    filepath: 'No File selected!',
        foundIssues: "",
        foundIssuesFixableWithUpdate: "",
        chartData:{
            labels: ['1', '2', '3', '4','55','6'],
            datasets:[
                                        {
                    label: 'Vulnerabilities',
                    data:[12,14,15,16,18,19],
                                        }
                                ]}}}

In the actual render function, the chart is implemented as following: 在实际的渲染功能中,该图表的实现如下:

Render 给予

 render() {
     return (
      <div className="App">
        <div className="App-header">
          <img src={logo} className="App-logo" alt="logo" />
        </div>
         <div className ="Chart">
            <Bar data={this.state.chartData}/>
         </div>
   </div>
    );
  }

As ive already mentioned, the graph gets displayed correctly, as you can see in the following picture: 正如我已经提到的,该图将正确显示,如下图所示:

在此处输入图片说明

But unfortunately the tooltip on hovering does not work. 但是很遗憾,悬停工具提示不起作用。 Can anyone help me out? 谁能帮我吗?

I was able to narrow down the problem. 我能够缩小问题的范围。 My electron app config, in which i set the window to be borderless, seems to interfere with the tooltips. 我的电子应用程序配置(其中我将窗口设置为无边界)似乎干扰了工具提示。

This is the function which create the electron app: 这是创建电子应用程序的功能:

electron.js electron.js

function createWindow() {
  mainWindow = new BrowserWindow({frame: false, titleBarStyle: 'hidden' ,width: 800, height: 1000, backgroundColor: '#FFFFFF' });
  mainWindow.loadURL(
    isDev
      ? "http://localhost:3000"
      : `file://${path.join(__dirname, "../build/index.html")}`
  );

After the changing the window frame option to the following, the tooltips are working again: 将窗口框架选项更改为以下选项后,工具提示将再次起作用:

frame: false

So, for some reason, to have working tooltips with chartjs in an electron wrapped react app you need to enable the border window for the actual application. 因此,由于某种原因,要在电子包装的React应用程序中使用带有Chartjs的有效工具提示,您需要为实际应用程序启用边框窗口。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM