如何解决TypeError:anomalyData为null
我设法使Watson discovery API正常工作。但是,当我在UI搜索字段中输入搜索字符串并按Enter键时,收到以下错误:
TypeError: anomalyData is null
hasAnomalies
C:/technology/Watsondiscovery/watson-discovery-ui/discovery-nodejs/src/AnomalyDetection/index.jsx:41
38 | }
39 |
40 | static hasAnomalies(anomalyData) {
> 41 | return anomalyData.some(result => result.anomaly);
| ^ 42 | }
43 |
44 | static propTypes = {
AnomalyDetection
C:/technology/Watsondiscovery/watson-discovery-ui/discovery-nodejs/src/AnomalyDetection/index.jsx:64
61 |
62 | state = {
63 | showQuery: false,> 64 | showOverlay: !AnomalyDetection.hasAnomalies(this.props.anomalyData),| ^ 65 | };
66 |
67 | onShowQuery = () => {
Demo/this.fetchNewData/</<
C:/technology/Watsondiscovery/watson-discovery-ui/discovery-nodejs/src/demo.jsx:101
98 | }).then(response => {
99 | if (response.ok) {
100 | response.json().then(json => {
> 101 | this.setState({ loading: false,data: parseQueryResults(json) });
| ^ 102 | });
103 | } else {
104 | response
promise callback*Demo/this.fetchNewData/<
C:/technology/Watsondiscovery/watson-discovery-ui/discovery-nodejs/src/demo.jsx:100
97 | body: JSON.stringify(query),98 | }).then(response => {
99 | if (response.ok) {
> 100 | response.json().then(json => {
| ^ 101 | this.setState({ loading: false,data: parseQueryResults(json) });
102 | });
103 | } else {
discovery-nodejs / src / AnomalyDetection / index.jsx具有以下代码:
import React,{ Component } from 'react';
import classNames from 'classnames';
import { string,number,shape,arrayOf } from 'prop-types';
import {
ResponsiveContainer,LineChart,Line,XAxis,YAxis,Cartesiangrid,Tooltip,ComposedChart,} from 'recharts';
import moment from 'moment';
import WidgetHeader from '../WidgetHeader/index';
import QuerySyntax from '../QuerySyntax/index';
import NoContent from '../NoContent/index';
import AnomalyDot from './AnomalyDot';
import AnomalyTooltip from './AnomalyTooltip';
import NoAnomaliesOverlay from './NoAnomaliesOverlay';
import queryBuilder from '../query-builder';
export default class AnomalyDetection extends Component {
static widgetTitle() {
return 'Anomaly Detection';
}
static widgetDescription() {
return 'Anomalies - days with an unusually high number of mentions - can be detected in news articles over a specified timeframe.';
}
static formatDate(date) {
return moment(date).format('MM/DD');
}
static hasAnomaly(payload) {
return payload && payload.anomaly;
}
static hasAnomalies(anomalyData) {
return anomalyData.some(result => result.anomaly);
}
static propTypes = {
anomalyData: arrayOf(
shape({
key_as_string: string.isrequired,matching_results: number.isrequired,anomaly: number,})
).isrequired,query: shape({
text: string.isrequired,}).isrequired,colorLine: string.isrequired,};
static defaultProps = {
colorLine: '#00a78f',};
state = {
showQuery: false,showOverlay: !AnomalyDetection.hasAnomalies(this.props.anomalyData),};
onShowQuery = () => {
this.setState({ showQuery: true });
};
onShowResults = () => {
this.setState({ showQuery: false });
};
handleViewData = () => {
this.setState({ showOverlay: false });
};
render() {
const { query,anomalyData,colorLine } = this.props;
return (
<div>
{!this.state.showQuery ? (
<div className="anomaly-detection widget">
<WidgetHeader
title={AnomalyDetection.widgetTitle()}
description={AnomalyDetection.widgetDescription()}
onShowQuery={this.onShowQuery}
/>
{anomalyData.length > 0 ? (
<div className="anomaly-chart-container--div">
<ResponsiveContainer height={250}>
<LineChart
data={anomalyData}
className={classNames('anomaly-chart--svg',{
faded: this.state.showOverlay,})}
margin={{
...ComposedChart.defaultProps.margin,top: 15,right: 15,}}
>
<Line
type="linear"
dataKey="matching_results"
name="Matching Results"
stroke={colorLine}
strokeWidth="3"
dot={<AnomalyDot />}
activeDot={<AnomalyDot active />}
/>
<Cartesiangrid stroke="#ccc" />
<XAxis
dataKey="key_as_string"
tickFormatter={AnomalyDetection.formatDate}
tickLine={false}
/>
<YAxis domain={['auto','auto']} tickLine={false} />
<Tooltip
labelFormatter={AnomalyDetection.formatDate}
content={<AnomalyTooltip />}
/>
</LineChart>
</ResponsiveContainer>
{this.state.showOverlay && (
<NoAnomaliesOverlay text={query.text} onViewData={this.handleViewData} />
)}
</div>
) : (
<NoContent query={query} message="There are no analytics available for your query." />
)}
</div>
) : (
<QuerySyntax
title={AnomalyDetection.widgetTitle()}
query={queryBuilder.build(query,queryBuilder.widgetQueries.anomalyDetection)}
response={{ results: anomalyData }}
onGoBack={this.onShowResults}
/>
)}
</div>
);
}
}
我确实搜索了此错误。找不到解决方案。对于解决此错误的任何帮助,将不胜感激。
谢谢 R
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。