Skip to content

如何修改柱状图hover时的背景样式 #5011

Answered by pearmini
liuzhaoxu1996 asked this question in Q&A
Discussion options

You must be logged in to vote

v5 里面可以通过 mark.state API 去修改高亮时候背景的颜色:

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

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

chart
  .interval()
  .data({
    type: 'fetch',
    value:
      'https://gw.alipayobjects.com/os/bmw-prod/fb9db6b7-23a5-4c23-bbef-c54a55fee580.csv',
    transform: [{ type: 'slice', start: 0, end: 5 }],
  })
  .encode('x', 'letter')
  .encode('y', 'frequency')
  .scale('y', { nice: true })
  .axis('y', { labelFormatter: '.0%' })
  .state({
    active: { // 设置高亮时候背景的颜色
      backgroundFill: 'red',
      backgroundRadius: 10,
    },
  });

chart.interaction('elementHighlight', {
  background: true, // 显示背景
});

chart.render();

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@liuzhaoxu1996
Comment options

Answer selected by hustcc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants