antvis/G2

一个图可以有两个Tooltip吗? #4859

luohaley posted onGitHub

<!-- Thank you for your pull request. Please review below requirements. Bug fixes and new features should include tests and possibly benchmarks. Contributors guide: https://github.com/antvis/g2/blob/master/CONTRIBUTING.md 感谢您贡献代码。请确认下列 checklist 的完成情况。 Bug 修复和新功能必须包含测试,必要时请附上性能测试。 Contributors guide: https://github.com/antvis/g2/blob/master/CONTRIBUTING.md -->

Checklist

<!-- Remove items that do not apply. For completed items, change [ ] to [x]. -->

  • npm test passes
  • benchmarks are included
  • commit message follows commit guidelines
  • documents are updated
Description of change

<!-- Provide a description of the change below this comment. -->


暂时不支持,v5 5月底会支持这个功能

posted by pearmini about 2 years ago

image 像这个怎么加两个tooltip? 代码如下

import React, { useEffect } from 'react';
import { Chart } from '@antv/g2';


const DoubleArea: React.FC = (props) => {

  const data = [
    { time: '16', north: 0, south: 0 },
    { time: '18', north: 7, south: -8 },
    { time: '20', north: 6, south: -7 },
    { time: '22', north: 9, south: -8 },
    { time: '00', north: 5, south: -7 },
    { time: '02', north: 8, south: -5 },
    { time: '04', north: 6, south: -7 },
    { time: '06', north: 7, south: -8 },
    { time: '08', north: 9, south: -9 },
    { time: '10', north: 6, south: -9 },
    { time: '12', north: 5, south: -9 },

  ];

  const handleInit = () => {
    const chart = new Chart({
      container: 'container',
      theme: 'classic',
      autoFit: true,
    });

    chart.data(data);

    chart
      .area()
      .encode('x', (d: any) => d.time)
      .encode('y', 'north')
      .tooltip(false)
      .style('fill', 'l(270) 0:#BAC922 1:#8CA522');
    chart
      .area()
      .encode('x', (d: any) => d.time)
      .encode('y', 'south')
      .tooltip(false)
      .style('fill', 'l(90) 0:#B1EE33 1:#8BE633');

    chart
      .line()
      .encode('x', (d: any) => d.time)
      .encode('y', 'north')
      .tooltip({
        items: [
          'north', // 第一个 item
        ],
      })
      .style('stroke', '#194BFB')
      .style('strokeWidth', 1);
    chart
      .line()
      .encode('x', (d: any) => d.time)
      .encode('y', 'south')
      .tooltip({
        items: [
          'south', // 第二个 item
        ],
      })
      .style('stroke', '#3DD598')
      .style('strokeWidth', 1);
    chart.interaction('tooltip', {
      // 设置 Tooltip 的位置
      position: 'right',
    });
    chart.render();
  };
  useEffect(() => {
    handleInit();
  }, []);
  const itemStyle = {
    width: '555px',
    height: '220px',
    marginTop: '24px',
  };
  return (
    <>
      <div style={itemStyle} id='container' />
    </>
  );
};

export default DoubleArea;

要实现的效果是下图1 2都有自己的tooltip,而且这两个tooltip是分开的。怎么实现? image

posted by luohaley almost 2 years ago

@luohaley 我添加了一个例子:https://github.com/antvis/G2/pull/6318 ,你可以看看。

posted by pearmini 10 months ago

Fund this Issue

$0.00
Funded

Pull requests