为了账号安全,请及时绑定邮箱和手机立即绑定

关于echarts的xAxis.data和series.data的数据用后端返回的数组动态替换之后无法显示的问题

var main = document.getElementById('main') as HTMLDivElementvar myChart = echarts.init(main);// specify chart configuration item and datavar option = {title: {text: 'Company Compare Charts'},toolbox: {show: true,feature: {saveImage: {show: true},magicType: {type: ['bar', 'line', 'pie']}}},legend: {data:['Stock Price']},xAxis: {data: this.timeline},yAxis: {},series: [{name: 'Stock Price',type: 'bar',data: this.priceStack,markPoint: {data: [{type: 'max', name: 'max'},{type: 'min', name: 'min'}]},markLine: {data: [{type: 'average', name: 'average'}]}}]};// use configuration item and data specified to show chartmyChart.setOption(option);
console.log(response.data.stockPriceDetails)for(let json of response.data.stockPriceDetails){this.timeline.push(json.currentDate + ' ' + json.currentTime)this.priceStack.push(json.currentPrice)}console.log(this.timeline)console.log(this.priceStack)
public timeline: any[] = []public priceStack: any[] = []

http://img1.sycdn.imooc.com//5dea765e0001982910420204.jpghttp://img1.sycdn.imooc.com//5dea768d0001dbd813800634.jpg

正在回答

3 回答

不能用全局变量方式传递data,用传参的方法。参考:

https://www.echartsjs.com/zh/tutorial.html#%E5%BC%82%E6%AD%A5%E6%95%B0%E6%8D%AE%E5%8A%A0%E8%BD%BD%E5%92%8C%E6%9B%B4%E6%96%B0

0 回复 有任何疑惑可以回复我~

确实如您所说 将从后端获取到返回值在response中重绘即重新myChart.setOption即可 感谢fan哥到友情指导^_^

0 回复 有任何疑惑可以回复我~

举报

0/150
提交
取消
Echarts3.0入门基础与实战
  • 参与学习       53468    人
  • 解答问题       168    个

Echarts3.0入门视频教程,带你领略高逼格数据可视化的魅力

进入课程

关于echarts的xAxis.data和series.data的数据用后端返回的数组动态替换之后无法显示的问题

我要回答 关注问题
意见反馈 帮助中心 APP下载
官方微信