微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

ChartJS道具数据未定义错误ReactJS

如何解决ChartJS道具数据未定义错误ReactJS

我正在尝试将Jira门票数据传递到饼图组件中。但是,我遇到此错误

 Failed prop type: The prop `data` is marked as required in `ChartComponent`,but its value is `undefined`

请忽略: 看起来您的帖子大部分是代码;请添加更多详细信息。 看起来您的帖子大部分是代码;请添加更多详细信息。 看起来您的帖子大部分是代码;请添加更多详细信息。 看起来您的帖子大部分是代码;请添加更多详细信息。 看起来您的帖子大部分是代码;请添加更多详细信息。

Error

import React,{ useContext,useEffect,useState } from 'react'
import { LoadingContext } from '../../../context/loading-context'
import { SnackbarContext } from '../../../context/snackbar-context'
import { UserContext } from '../../../context/user-context'
import {get} from '../../../functions/Rest'
import { Pie } from 'react-chartjs-2'

const defects = props => {

    const loading = useContext(LoadingContext)
    const snackbar = useContext(SnackbarContext)
    const user = useContext(UserContext)
  

    const [jiraticketsData,setJiraTicketsData] = useState('')


    useEffect(() => {
        async function onLoadJiraTicketData() {
          loading.setLoading(true)
          const results = get(`get_jira_tickets`,user.user)
          if (results.status === 0) {
              setJiraTicketsData(results.data)
          } else if (results.status >= 20 && results.status <= 30 ){
            snackbar.statusCheck(results)
            user.setSessionTokenMatches(false)
          } else {
            snackbar.statusCheck(results)
          }
          loading.setLoading(false)
        }
        onLoadJiraTicketData()

      },[])


  return (
    <div className='defects'>
      <Pie data={jiraticketsData.pie_chart} />
      </div>
  )
}


export default defects

我正在尝试访问pie_chart数组数据:

Pie chart array

这是ChartComponent代码,如果需要的话:

import * as React from "react";
import * as chartjs from "chart.js";

export type ChartDataFunction<T extends chartjs.ChartData> = (
  element: HTMLElement
) => T;
export type ChartData<T extends chartjs.ChartData> = ChartDataFunction<T> | T;

export interface ChartComponentProps {
  data: ChartData<chartjs.ChartData>;
  type?: chartjs.ChartType;
  getDatasetAtEvent?(e: any): void;
  getElementAtEvent?(e: any): void;
  getElementsAtEvent?(e: any): void;
  height?: number;
  legend?: chartjs.ChartLegendOptions;
  onElementsClick?(e: any): void; // alias for getElementsAtEvent (backward compatibility)
  options?: chartjs.ChartOptions;
  plugins?: object[];
  redraw?: boolean;
  width?: number;
  datasetKeyProvider?: (any: any) => any;
}

export interface LinearComponentProps extends ChartComponentProps {
  data: ChartData<chartjs.ChartData>;
}

export default class ChartComponent<
  P extends ChartComponentProps
> extends React.Component<P,{}> {
  chartInstance: chartjs;
}

export class Doughnut extends ChartComponent<ChartComponentProps> {}

export class Pie extends ChartComponent<ChartComponentProps> {}

export class Line extends ChartComponent<LinearComponentProps> {}

export class Scatter extends ChartComponent<ChartComponentProps> {}

export class Bar extends ChartComponent<LinearComponentProps> {}

export class HorizontalBar extends ChartComponent<ChartComponentProps> {}

export class Radar extends ChartComponent<ChartComponentProps> {}

export class Polar extends ChartComponent<ChartComponentProps> {}

export class Bubble extends ChartComponent<ChartComponentProps> {}

export var defaults: {
  global: chartjs.ChartOptions & chartjs.ChartFontOptions;
  [key: string]: any;
};

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。