Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

堆叠图设置颜色 #5928

Closed
YY88Xu opened this issue Dec 13, 2023 · 1 comment
Closed

堆叠图设置颜色 #5928

YY88Xu opened this issue Dec 13, 2023 · 1 comment

Comments

@YY88Xu
Copy link

YY88Xu commented Dec 13, 2023

问题描述

堆叠图怎么设置不同 lable 的颜色呢?

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

const chart = new Chart({
  container: 'container',
  autoFit: true,
});
const data = [
    {
      "month": "2023年1月",
      "label": "R4",
      "value": 10,
      color: 'red',
    },
    {
      "month": "2023年1月",
      "label": "R5",
      "value": 30,
      color: 'yellow',
    },
    {
      "month": "2023年1月",
      "label": "R6",
      color: 'green',
      "value": 32
    },
    {
      "month": "2023年2月",
      "label": "R4",
      color: 'red',
      "value": 10
    },
    {
      "month": "2023年2月",
      "label": "R5",
      color: 'yellow',
      "value": 60
    },
    {
      "month": "2023年2月",
      "label": "R6",
      color: 'green',
      "value": 40
    },
  ]
chart
  .interval()
  .data(data)
  .transform({ type: 'stackY' })
  .transform({ type: 'sortX', by: 'y', reverse: true })
  .encode('x', 'month')
  .encode('y', 'value')
  .encode('color', 'color')

chart.render();
image

重现链接

No response

重现步骤

No response

预期行为

No response

平台

  • 操作系统: [macOS, Windows, Linux, React Native ...]
  • 网页浏览器: [Google Chrome, Safari, Firefox]

屏幕截图或视频(可选)

No response

补充说明(可选)

No response

@hustcc
Copy link
Member

hustcc commented Dec 14, 2023

chart
  .interval()
  .data(data)
  .transform({ type: 'stackY' })
  .transform({ type: 'sortX', by: 'y', reverse: true })
  .encode('x', 'month')
  .encode('y', 'value')
  .encode('series', 'color')
  .style('fill', (d) => d.color)  // 👈🏻

@hustcc hustcc closed this as completed Dec 14, 2023
@antvis antvis locked and limited conversation to collaborators Dec 14, 2023
@hustcc hustcc converted this issue into discussion #5929 Dec 14, 2023

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants