我要在Android(Java版本)上的TeeChart中添加一个ColorLine Tool。一切都很好,除了我不能用 DASH 风格画线。
这是我的代码片段:
ColorLine closeLabelLine = new ColorLine(chart.getChart());
closeLabelLine.setValue(closeValue);
closeLabelLine.setAxis(chart.getAxes().getRight());
closeLabelLine.getPen().setStyle(DashStyle.DASH); //Seems like no effect!
closeLabelLine.getPen().setColor(CLOSE_LABEL_COLOR);
我做错了什么?
更新:
在通过设置chart.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
和closeLabelLine.setDraw3D(false);
测试 Yeray 的解决方案后,一切似乎都正常工作。但是在添加轴中断工具后,我遇到了以下异常:
java.lang.IllegalStateException: Underflow in restore
at android.graphics.Canvas.native_restore(Native Method)
at android.graphics.Canvas.restore(Canvas.java:497)
at com.steema.teechart.android.Graphics3DAndroid.restore(Graphics3DAndroid.java:356)
at com.steema.teechart.android.Graphics3DAndroid.unClip(Graphics3DAndroid.java:362)
at com.steema.teechart.tools.AxisBreaksTool.drawRectangle(AxisBreaksTool.java:410)
at com.steema.teechart.tools.AxisBreaksTool.doDrawLine(AxisBreaksTool.java:720)
at com.steema.teechart.tools.AxisBreaksTool.chartEvent(AxisBreaksTool.java:748)
at com.steema.teechart.Chart.broadcastToolEvent(Chart.java:1035)
at com.steema.teechart.Chart.drawAllSeries(Chart.java:813)
at com.steema.teechart.Chart.drawAxesSeries(Chart.java:802)
at com.steema.teechart.Chart.internalDraw(Chart.java:782)
at com.steema.teechart.Chart.paint(Chart.java:2169)
at com.steema.teechart.Chart.paint(Chart.java:2185)
at com.steema.teechart.TChart.onDraw(TChart.java:326)
at android.view.View.draw(View.java:15114)
at android.view.View.buildDrawingCache(View.java:14343)
at android.view.View.updateDisplayListIfDirty(View.java:14029)
at android.view.View.getDisplayList(View.java:14071)
at android.view.View.draw(View.java:14838)
at android.view.ViewGroup.drawChild(ViewGroup.java:3404)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3198)
at android.view.View.updateDisplayListIfDirty(View.java:14043)
at android.view.View.getDisplayList(View.java:14071)
at android.view.ViewGroup.recreateChildDisplayList(ViewGroup.java:3388)
at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:3367)
at android.view.View.updateDisplayListIfDirty(View.java:14008)
at android.view.View.getDisplayList(View.java:14071)
at android.view.ViewGroup.recreateChildDisplayList(ViewGroup.java:3388)
at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:3367)
at android.view.View.updateDisplayListIfDirty(View.java:14008)
at android.view.View.getDisplayList(View.java:14071)
at android.view.ViewGroup.recreateChildDisplayList(ViewGroup.java:3388)
at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:3367)
at android.view.View.updateDisplayListIfDirty(View.java:14008)
at android.view.View.getDisplayList(View.java:14071)
at android.view.ViewGroup.recreateChildDisplayList(ViewGroup.java:3388)
at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:3367)
at android.view.View.updateDisplayListIfDirty(View.java:14008)
at android.view.View.getDisplayList(View.java:14071)
at android.view.ViewGroup.recreateChildDisplayList(ViewGroup.java:3388)
at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:3367)
at android.view.View.updateDisplayListIfDirty(View.java:14008)
at android.view.View.getDisplayList(View.java:14071)
at android.view.ViewGroup.recreateChildDisplayList(ViewGroup.java:3388)
at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:3367)
at android.view.View.updateDisplayListIfDirty(View.java:14008)
at android.view.View.getDisplayList(View.java:14071)
at android.view.ViewGroup.recreateChildDisplayList(ViewGroup.java:3388)
at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:3367)
at android.view.View.updateDisplayListIfDirty(View.java:14008)
at android.view.View.getDisplayList(View.java:14071)
at android.view.ViewGroup.recreateChildDisplayList(ViewGroup.java:3388)
at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:3367)
at android.view.View.updateDisplayListIfDirty(View.java:14008)
at android.view.View.getDisplayList(View.java:14071)
at android.view.ViewGroup.recreateChildDisplayList(ViewGroup.java:3388)
at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:3367)
at android.view.View.updateDisplayListIfDirty(View.java:14008)
at android.view.View.getDisplayList(View.java:14071)
at android.view.ViewGroup.recreateChildDisplayList(ViewGroup.java:3388)
at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:3367)
我发现chart.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
导致图表无异常地工作,但 ColorLine 显示为实心,而不是根据需要使用破折号。
有两个技巧可以帮助您获得所需的结果:
-
首先注意这个和这个。如果要绘制 DASH 线,则必须从 API 11 禁用硬件加速:
if (Build.VERSION.SDK_INT>10) chart.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
-
另请注意,默认情况下,
ColorLine
工具会绘制侧面和背面。要禁用此功能并仅绘制前线:closeLabelLine.setDraw3D(false);
更新:
正如您在问题的更新部分中所说,使用建议的修复程序在使用时会产生错误 AxisBreaksTool
.
实际上,我发现在剪辑某些内部函数时缺少一些canvas.save()
调用,从而产生了此问题,也可能出现其他崩溃。
我已经在内部源中添加了所需的调用,在这里似乎对我来说效果很好。
但是,我想不出使其在当前版本中工作的解决方法,因此恐怕您将不得不等待下一个维护版本(您可以向"steema dot com 的信息"发送邮件以请求测试版本)。
更新 2:
我最初修改了 TeeChart 源,以便在将笔设置为 DASH 样式时在内部禁用硬件加速。但是setLayerType
是在 API 11 中实现的,因此,为了保留 API 7 对 TeeChart 的支持,我不得不将其删除,并在必要时让开发人员执行此操作。