Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何避免悬停元素chartjs触发下一个元素的悬停_Javascript_Reactjs_Charts_React Chartjs - Fatal编程技术网

Javascript 如何避免悬停元素chartjs触发下一个元素的悬停

Javascript 如何避免悬停元素chartjs触发下一个元素的悬停,javascript,reactjs,charts,react-chartjs,Javascript,Reactjs,Charts,React Chartjs,我需要为我的图表中的条形图显示独立的悬停效果 问题 当我在其中一个栏上悬停时,下一个栏会显示他的悬停风格 如果我将黑色的悬停,它应该会变浅,但蓝色的则不能改变,除非我将其悬停 这是我的密码。没有模拟数据 我尝试了hover:()=>{}和hoverBackgroundColor但是它总是触发bot条的悬停样式 这是完整的图表 预期行为 当我将鼠标悬停在黑色条上时,它会将他的颜色更改为任何其他颜色,例如“红色” 但是蓝色的应该保持不变,当我在蓝色上悬停时,它应该把它的颜色改成其他颜色,例如“绿

我需要为我的图表中的条形图显示独立的悬停效果

问题

当我在其中一个栏上悬停时,下一个栏会显示他的悬停风格

如果我将黑色的悬停,它应该会变浅,但蓝色的则不能改变,除非我将其悬停

这是我的密码。没有模拟数据

我尝试了
hover:()=>{}
hoverBackgroundColor
但是它总是触发bot条的悬停样式

这是完整的图表

预期行为

当我将鼠标悬停在黑色条上时,它会将他的颜色更改为任何其他颜色,例如“红色”

但是蓝色的应该保持不变,当我在蓝色上悬停时,它应该把它的颜色改成其他颜色,例如“绿色”

import React from 'react';
import { Bar } from 'react-chartjs-2';
import { Wrapper, LegendsWrapper } from './style';
import Legend from './Legend/Legend';

const Chart = ({ labels, graphData, colors = ['#17C7D6', '#02193D'] }) => {
  const innerData = {
    labels,
    datasets: graphData.map(({ category, data }, i) => ({
      label: category,
      data,
      backgroundColor: Array(data.length).fill(colors[i]),
      yAxisID: category,
    })),
  };

  const options = {
    tooltips: {
      filter: tooltipItem => tooltipItem.datasetIndex === 0,
      backgroundColor: `#fff`,
      titleFontFamily: `var(--main-font)`,
      titleFontColor: '#000',
      bodyFontFamily: `var(--main-font)`,
      bodyFontSize: 10,
      bodyFontColor: `#888888`,
      // mode: 'nearest',
      cornerRadius: 4,
      position: 'nearest',
    },
    onHover: (e, el) => {
      const section = el[0];
      const currentStyle = e.target.style;
      console.log(e.target);

      currentStyle.color = section && section._start ? 'red' : 'green'; // <-- default here
      currentStyle.cursor = section ? 'pointer' : 'default'; // <-- default here
    },
    layout: {
      padding: {
        left: 0,
        right: 0,
        top: 0,
        bottom: 10,
      },
    },
    legend: {
      display: false,
    },
    maintainAspectRatio: false,
    scales: {
      pointLabels: {
        fontStyle: 'bold',
      },
      xAxes: [
        {
          categoryThickness: 200,
          barThickness: 12,
          gridLines: {
            // display: false,
            drawOnChartArea: false,
            tickMarkLength: 4,
            color: `#052442`,
          },
          ticks: {
            min: 0,
            fontFamily: `var(--main-font)`,
            fontSize: 8,
            fontColor: `#9E9E9E`,
            padding: 15,
            maxRotation: -45,
            minRotation: -45,
          },
        },
      ],
      yAxes: [
        {
          id: graphData[0].category,
          ticks: {
            min: 0,
            fontFamily: `var(--main-font)`,
            fontSize: 8,
            fontColor: `#6e6e6e`,
            padding: 5,
          },
          gridLines: {
            drawOnChartArea: false,
            drawBorder: true,
            tickMarkLength: 4,
            color: `#052442`,
          },
        },
        {
          id: graphData[1].category,
          position: 'right',
          ticks: {
            fontFamily: `var(--main-font)`,
            fontSize: 8,
            fontColor: `#6e6e6e`,
            padding: 5,
          },
          gridLines: {
            // display: false,g
            drawOnChartArea: false,
            drawBorder: true,
            tickMarkLength: 4,
            color: `#052442`,
          },
        },
      ],
    },
  };

  return (
    <Wrapper>
      <LegendsWrapper>
        {graphData.map(({ category }, i) => (
          <Legend text={category} color={colors[i]} />
        ))}
      </LegendsWrapper>

      <Bar data={innerData} options={options} />
    </Wrapper>
  );
};

export default Chart;
labels: ['1950', '1960', '1970', '1980', '1990', '2000', '2010'],
            graphData: [
              {
                category: 'EHR Patients',
                data: [11500, 11600, 14000, 19700, 13000, 3000, 2300],
              },
              {
                category: 'IGM Patients',
                data: [1.2, 3.8, 16.2, 19, 11.7, 1.4, 1.2],
              },
            ],