antvis/G2

Do you want to work on this issue?

You can request for a bounty in order to promote it!

[Question] G2 滚动缩小放大 & 标记尺 #5437

liangchaofei posted onGitHub

Q1

G2中如何实现 鼠标滚动缩小和放大效果。 类似X6中的滚轮缩放功能:https://x6.antv.vision/zh/docs/tutorial/basic/mousewheel

Q2

G2中如何实现 在折线图中增加垂直的标注尺,标注尺可以拖拽。分别支持单标尺和双标尺


Q1 占位,需要调研一下。

核心逻辑是,通过监听 plot 事件,然后针对事件去计算 scale.domain 的大小,然后重新 render。

import { Chart } from '@antv/g2';

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

chart
  .point()
  .data({
    type: 'fetch',
    value:
      'https://gw.alipayobjects.com/os/basement_prod/6b4aa721-b039-49b9-99d8-540b3f87d339.json',
  })
  .encode('x', 'height')
  .encode('y', 'weight')
  .encode('color', 'gender')
;

// 这里
chart.on('plot:click', (e) => {
  console.log(e);
  chart.scale('x', { domain: [0, 10] })
  chart.render()
});

chart.render();
posted by hustcc over 1 year ago

Q2:G2 中如何实现 在折线图中增加垂直的标注尺,标注尺可以拖拽。分别支持单标尺和双标尺

标尺线可使用 标注去实现,参考 DEMO,但是拖拽的能力,需要外部监听事件去实现。

image

chart.on('lineY:click', (e) => {
  console.log(e);
})
posted by hustcc over 1 year ago

Fund this Issue

$0.00
Funded
Only logged in users can fund an issue

Pull requests