echarts报错:"Error: yAxis "0" not found"
问题描述
根据时间选择器的选定制,后台数据进行柱状图渲染,初次渲染成功;
更换请求数据后,再次请求,再次渲染,浏览器报错:
Error: yAxis "0" not found
at cartesian2d (echarts.js:22865)
at createListFromArray (echarts.js:22770)
at ExtendedClass.getInitialData (echarts.js:28903)
at ExtendedClass.init (echarts.js:7461)
at ExtendedClass.<anonymous> (echarts.js:2306)
at Array.forEach (<anonymous>)
at each (echarts.js:3060)
at ExtendedClass.visitComponent (echarts.js:2267)
at Function.entity.topologicalTravel (echarts.js:6189)
at ExtendedClass.mergeOption (echarts.js:2236)
问题出现的环境背景及自己尝试过哪些方法
环境:
"angular-route": "1.5.8",
"bootstrap": "^3.3.7",
"angular": "1.5.8",
"echarts": "3.3.2",
"angular-sanitize": "1.6.4",
"d3": "3.5.17",
"ng-file-upload-shim": "12.2.13",
"bootstrap-datetimepicker": "0.0.11",
"md5": "0.7.2",
"angular-bootstrap": "1.3.2",
"angular-animate": "1.6.4",
"pdfjs-build": "0.9.0",
"jquery": "3.2.1",
"jQuery.print": "1.5.1",
"jquery.cookie": "1.4.1",
"moment": "2.9.0",
"bootstrap-daterangepicker": "2.1.25",
"bootstrap-wysiwyg": "master",
"angular-ivh-treeview": "^v1.1.0",
"angular-ui-tree": "^v2.22.6",
"html2canvas": "^0.4.1",
"font-awesome": "^5.6.3"
相关代码
// 请把代码文本粘贴到下方(请勿用图片代替代码)
响应的数据格式:
{"2019-04-18 ":{"1":"1"},"2019-05-23 ":{"1":"1"}}
代码结构:
var timeRangeData = function (){
var columnGraph = echarts.init($columnGraph[0]);
columnGraph.showLoading();
APIService.getHistoryDateKpi({
'startDate': $scope.enterGourpDateRange.timeRange[0], // 开始时间
'endDate': $scope.enterGourpDateRange.timeRange[1], //结束时间
'type': $scope.filterNumKind[$scope.defaultFilterkind] // x轴渲染用的文字
}).then(function (msg) {
var type = $scope.filterNumKind[$scope.defaultFilterkind] //
var columnData = filterColumnData(angular.copy(msg), type) //数据处理方法
drawColumnGraph(columnGraph, columnData, type) //画柱状图方法
columnGraph.hideLoading();
})
}
/* 柱状图数据处理 */
const filterColumnData = function (org, type) {
let columnData = [];
Object.keys(org).forEach((key) => {
Object.keys(org[key]).forEach((ele) => columnData.push({
name: $scope.historyDateMapping[ele],
data: [...org[key][ele]],
num: key
}))
})
// 数据合成
columnData.map(ele => {
ele.type = 'bar';
ele.stack = '总量';
ele.label = {};
ele.label.normal = {
show: true,
position: 'insideRight'
}
})
return columnData;
}
/* 画柱状图 */
var drawColumnGraph = function (columnGraph, allData, dateType) {
let dateNum = [];
allData.map((ele) => dateNum.push(ele.num));
columnGraph.setOption({
series: allData,
xAxis: {
type: 'category',
data: dateNum
}
})
}
你期待的结果是什么?实际看到的错误信息又是什么?
期望能够正确展示.
实际看到的错误信息是
Error: yAxis "0" not found
at cartesian2d (echarts.js:22865)
at createListFromArray (echarts.js:22770)
at ExtendedClass.getInitialData (echarts.js:28903)
at ExtendedClass.init (echarts.js:7461)
at ExtendedClass.<anonymous> (echarts.js:2306)
at Array.forEach (<anonymous>)
at each (echarts.js:3060)
at ExtendedClass.visitComponent (echarts.js:2267)
at Function.entity.topologicalTravel (echarts.js:6189)
at ExtendedClass.mergeOption (echarts.js:2236)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
报错的原因是,我画柱状图时,只设置了xAxis和series,没设置neme,type等属性,这既是粗心的后果....