当另一个div位于图表上方时,使highcharts图例保持响应

时间:2019-04-16 18:50:18

标签: reactjs highcharts sass

我想在HighCharts极坐标图边距的四个角显示html按钮。我能够使用CSS在图表div上分层放置按钮。但是,这样做会导致图表图例项不响应鼠标单击。

这是其中一个按钮的代码示例:

<div className="pop-chart-button pop-chart-button-top pop-chart-button-left">
  <a role="button" onClick={this.showBrandQuadrantChart}>
    <img src={expandImageUrl} alt="expand" /> BRAND
  </a>
</div>

是否有某种方法可以使图例项对鼠标单击无响应?

2 个答案:

答案 0 :(得分:0)

仅凭猜测就不会看到您的CSS代码,按钮z-index位于图表下方。将按钮设置为较高的z-index可能会解决此问题。

答案 1 :(得分:0)

通过为图表和按钮div设置z-index并将图表div放在包含按钮的div之后,解决了我的问题。

以下是scss样式:

.pop-kahn-chart-container {
  position: relative;

  .pop-chart {
    z-index: 99;
  }

  .pop-chart-buttons {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;

    .pop-chart-button {
      font-family: 'Montserrat', sans-serif;
      font-style: normal;
      font-size: 0.86rem;
      font-weight: 600;
      position: absolute;
      z-index: 9;

      a {
        border-radius: 2px;
        padding: 2px 8px;
        color: $bp-green;
      }

      a:hover {
        background-color: $bp-gray2;
      }

      img {
        width: 19px;
        height: 19px;
        vertical-align: center;
        position: relative;
        top: -3px;
      }

      @include media-breakpoint-down(lg) {
        font-size: 0.6rem;

        img {
          width: 14.25px;
          height: 14.25px;
          top: -2.25px;
        }
      }
    }

    .pop-chart-button-top {
      top: 10%;
    }

    .pop-chart-button-bottom {
      top: 85%;
    }

    .pop-chart-button-left {
      left: 5%;
    }

    .pop-chart-button-right {
      left: 75%;
    }
  }
}

以下是使用叠加按钮呈现图表的代码:

<div className="pop-kahn-chart-container">
  <div className="pop-chart-buttons">
    <div className="pop-chart-button pop-chart-button-top pop-chart-button-left">
      <a role="button" onClick={this.showBrandQuadrantChart}>
        <img src={expandImageUrl} alt="expand" /> BRAND
      </a>
    </div>

    <div className="pop-chart-button pop-chart-button-top pop-chart-button-right">
      <a role="button" onClick={this.showExperienceQuadrantChart}>
        <img src={expandImageUrl} alt="expand" /> EXPERIENCE
      </a>
    </div>

    <div className="pop-chart-button  pop-chart-button-bottom pop-chart-button-left">
      <a role="button" onClick={this.showLowPriceQuadrantChart}>
        <img src={expandImageUrl} alt="expand" /> LOW PRICE
      </a>
    </div>

    <div className="pop-chart-button pop-chart-button-bottom pop-chart-button-right">
      <a role="button" onClick={this.showFrictionlessQuadrantChart}>
        <img src={expandImageUrl} alt="expand" /> FRICTIONLESS
      </a>
    </div>
  </div>

  <div className="pop-chart">
    <HighchartsReact highcharts={Highcharts} options={options} />
  </div>
</div>