如何在TeeChart 中用DASH 样式绘制ColorLine?

How to draw ColorLine in TeeChart with DASH style?

我正在尝试在 Android(Java 版本)的 TeeChart 中添加一个 ColorLine 工具。 一切正常,除了我无法使用 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 显示为实线,而不是所需的破折号。

有两个提示可以帮助您获得理想的结果:

  • 第一注this and this。如果要绘制 DASH 线,则必须从 API 11:

    禁用硬件加速
    if (Build.VERSION.SDK_INT>10)
        chart.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
    
  • 另请注意 ColorLine 工具默认绘制侧面和背面。要禁用此功能并只绘制前线:

    closeLabelLine.setDraw3D(false);
    

更新:

正如您在问题的更新部分所说,使用建议的修复会在使用 AxisBreaksTool.
时产生错误 实际上,我发现在剪辑某些内部函数时缺少对 canvas.save() 的一些调用,从而产生了这个崩溃和其他崩溃。
我已经在内部资源中添加了所需的调用,它在这里对我来说似乎工作正常。
但是,我想不出使它在当前版本中工作的解决方法,所以恐怕您将不得不等待下一个维护版本(您可以发送邮件到 "info at steema dot com" 要求测试版本) .


更新 2:

我最初修改了 TeeChart 源以在将笔设置为 DASH 样式时在内部禁用硬件加速。但是 setLayerTypeimplemented in API 11 所以,为了保持 API 7 对 TeeChart 的支持,我不得不删除它并让开发人员在必要时这样做。