Skip to content

g2 v5.x 柱状图如何将不同的key堆叠到一起? #5186

Answered by pearmini
PS-panda asked this question in Q&A
Discussion options

You must be logged in to vote

可以使用 fold Data Transform.

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

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

chart
  .interval()
  .data({
    value: [
      { month: 'Jan', key1: 100, key2: 150, key3: 200 },
      { month: 'Feb', key1: 120, key2: 160, key3: 210 },
      { month: 'Mar', key1: 130, key2: 170, key3: 220 },
    ],
    transform: [{ type: 'fold', fields: ['key1', 'key2', 'key3'] }],
  })
  .encode('x', 'month')
  .encode('y', 'value')
  .encode('color', 'key')
  .transform({type:'stackY'})

chart.render();

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by pearmini
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