如何使用DASH风格在TeeChart中绘制ColorLine?

时间:2015-01-27 17:36:55

标签: java android teechart

我很想在我的TeeChart上添加ColorLine工具(Java版)。 一切正常,但我不能用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显示为实心,而不是根据需要使用短划线。

1 个答案:

答案 0 :(得分:2)

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

  • 首先注意thisthis。如果要绘制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:

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