hellocharts-android
hellocharts-android copied to clipboard
当折线图所有数据都是0的时候会没有显示
当折线图的数据全是0的时候,折线图会消失,这个问题怎么解决?
Hi, I'm not sure if I understand. Maybe the same case as in #143 and #169. Try to use custom viewport.
请问这个问题解决了吗?
var vp = Viewport().apply { for (line in data.lines) { for (value in line.values) { if (value.x < left) { left = value.x } if (value.x > right) { right = value.x } if (value.y < bottom) { bottom = value.y } if (value.y > top) { top = value.y } } } if(top == bottom){ if(top == 0f){ top = 1f }else{ top *= 2 } bottom = 0f } } lineChart.lineChartData = data lineChart.resetViewports() lineChart.maximumViewport = vp lineChart.currentViewport = vp
出现此种问题主要是因为Y轴所有值相同时候,设定的 maximumViewport 的top 和bottom 都一样导致绘制不出折线,所以需要先 resetViewports(),然后在赋值,亲测可行