首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >G2Plot具有nextjs。堆叠图不工作

G2Plot具有nextjs。堆叠图不工作
EN

Stack Overflow用户
提问于 2020-11-27 09:21:06
回答 1查看 363关注 0票数 0

我想使用G2plot创建一个叠加图。因此,我必须创建2个文件,一个用于组件。另一个用于将使用动态i调用组件的页面。

代码语言:javascript
复制
import React, { useEffect, useRef } from "react";
import { Bar } from "@antv/g2plot";

const data = [
  {
    year: "1991",
    value: 3,
    type: "Lon",
  },
  {
    year: "1992",
    value: 4,
    type: "Lon",
  },
  {
    year: "1993",
    value: 3.5,
    type: "Lon",
  },
  {
    year: "1994",
    value: 5,
    type: "Lon",
  },
  {
    year: "1995",
    value: 4.9,
    type: "Lon",
  },
  {
    year: "1996",
    value: 6,
    type: "Lon",
  },
  {
    year: "1997",
    value: 7,
    type: "Lon",
  },
  {
    year: "1998",
    value: 9,
    type: "Lon",
  },
  {
    year: "1999",
    value: 13,
    type: "Lon",
  },
  {
    year: "1991",
    value: 3,
    type: "Bor",
  },
  {
    year: "1992",
    value: 4,
    type: "Bor",
  },
  {
    year: "1993",
    value: 3.5,
    type: "Bor",
  },
  {
    year: "1994",
    value: 5,
    type: "Bor",
  },
  {
    year: "1995",
    value: 4.9,
    type: "Bor",
  },
  {
    year: "1996",
    value: 6,
    type: "Bor",
  },
  {
    year: "1997",
    value: 7,
    type: "Bor",
  },
  {
    year: "1998",
    value: 9,
    type: "Bor",
  },
  {
    year: "1999",
    value: 13,
    type: "Bor",
  },
];

const Main = (
  {
    // data,
    // xAxis = "xAxis",
    // yAxis = "yAxis",
    // color = "#0D0E68",
  }
) => {
  const containerRef = useRef(null);
  let stackedBarPlot;
  useEffect(() => {
    stackedBarPlot = new Bar(containerRef.current, {
      data: data.reverse(),
      isStack: true,
      xField: "value",
      yField: "year",
      seriesField: "type",
      autoFit: true,
      label: {
        position: "left", // 'left', 'middle', 'right'
        layout: [
          { type: "interval-adjust-position" },
          { type: "interval-hide-overlap" },
          { type: "adjust-color" },
        ],
      },
    });
  }, []);

  useEffect(() => {
    stackedBarPlot.render();
  }, []);
  return (
    <>
      <div ref={containerRef}></div>
    </>
  );
};

export default Main;

将动态导入的文件

代码语言:javascript
复制
import React from "react";
import dynamic from "next/dynamic";
const Main = () => {
  const StackedBar = dynamic(
    () => import("../../../src/Components/StackedBar"),
    {
      ssr: false,
    }
  );
  return (
    <>
      <StackedBar />
    </>
  );
};
export default Main;

PS。我正在使用nextjs 10,这里是我期望的行为https://codesandbox.io/s/optimistic-banach-up3i0?file=/index.js的代码框

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-11-29 14:33:33

结果,我不得不安装@antv/g2plot。在那之前,我有@antv/g2。安装包装后,每件工作都很完美。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/65034799

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档