You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在React TypeScript组件中正确使用Chartist v1.3.0?

问题:React TypeScript中使用Chartist v1.3.0报错

在React TypeScript组件中使用Chartist v1.3.0时遇到错误,错误截图如下:
Chartist错误截图1
Chartist错误截图2

我的组件代码如下:

import styled from "styled-components";
import 'chartist/dist/index.css';
import { LineChart } from 'chartist';


export const ChartPage = () => {

    new LineChart(
        '#chart',
        {
            labels: [1, 2, 3, 4, 5, 6, 7, 8],
            series: [[5, 9, 7, 8, 5, 3, 5, 4]]
        },
        {
            low: 0,
            showArea: true
        }
    );
      

    return (
        <div>
            <div id="chart"></div>
        </div>
    )
}

已尝试确保DOM元素存在等多种方法,但仍无法正常运行,希望有人协助解决该问题。

内容的提问来源于stack exchange,提问作者Nick

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.20 12:47:13