antvis/G2

Theme customisation not working. #6583

ashwin-gairola posted onGitHub

问题描述

It seems that registerTheme is no longer available as an export from @antv/g2. I am trying to create a stacked bar chart with a custom palette for bars:

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

    chart
      .interval()
      .data(data)
      .theme({
        // Merely an example to demonstrate that this is not applying.
        category10: [
          "red",
          "red",
          "red",
          "red",
          "red",
          "red",
          "red",
          "red",
          "red",
          "red",
        ],
      })
      .encode("x", xAxis)
      .encode("y", yAxis)
      .encode("color", series)
      .transform({ type: "stackY" })
      .axis({
        x: {
          labelAutoHide: true,
          labelAutoRotate: false,
        },
      })
      .scale("color", { palette: "category10" })
      .interaction("elementHighlight", { background: true })
      .interaction("brushFilter", true);

    chart
      .render()
      .then(() => {})
      .catch(() => {});

The field category10 is not getting updated. Also, on calling chart.getTheme(), I'm seeing undefined. Something's clearly broken here.

Also, can you please update your documentation for theme customization? How do you even create a custom theme anymore if registerTheme no longer exissts? The docs are extremely outdated and reference v4 and not v5.

重现链接

https://codesandbox.io/p/sandbox/333923

重现步骤

Simply create a chart and try to customize the color palette. It will not get applied.

预期行为

As per the above example, all bars in the chart should appear red or whatever custom palette you provide.

平台

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

屏幕截图或视频(可选)

No response

补充说明(可选)

No response


Please try removing the following code: .scale("color", { palette: "category10" }), as it will override the color palette you just set in the theme by default.

posted by interstellarmt about 2 months ago

⚠️ This issue has been automatically closed due to inactivity.

  • If the issue is still relevant and important to you, feel free to:
    1. Reopen with additional information
    2. Create a new issue with updated context
    3. Reference any related issues or discussions

We close inactive issues to keep our backlog manageable and focused on active issues.

Your contribution makes our project better! 🌟


⚠️ 由于长期无活动,此 issue 已被自动关闭。

  • 如果这个问题对您来说仍然重要,您可以:
    1. 重新打开并提供补充信息
    2. 创建一个新的 issue 并更新相关背景
    3. 关联相关的 issue 或讨论

为了更好地维护项目,我们需要定期清理不活跃的问题。

感谢您为开源添砖加瓦!🌟

posted by github-actions[bot] about 2 months ago

Fund this Issue

$0.00
Funded

Pull requests