I'm triyng to add a ColorLine Tool to my TeeChart on Android (Java version). Everything works fine except I can't make the line to be drawn with DASH style.
Here's my code snippet:
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);
What am I doing wrong?
UPDATE:
After testing Yeray's solution by setting chart.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
and closeLabelLine.setDraw3D(false);
everything seemed to be working. But after adding axis breaks tool I've got the following exception:
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)
I've found chart.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
causes the chart to work without exceptions, but ColorLine is displayed solid, not with dashes as desired.
There are two tips that may help you to get the desired result:
First note this and this. If you want to draw DASH lines, you'll have to disable the Hardware Acceleration from API 11:
if (Build.VERSION.SDK_INT>10)
chart.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
Also note the ColorLine
tool by default draws the sides and the back. To disable this and only draw the front line:
closeLabelLine.setDraw3D(false);
UPDATE:
As you say in the updated part of the question, using the fix suggested produces an error when using AxisBreaksTool
.
Actually, I found there were missing some calls to canvas.save()
when clipping in some internal functions, producing this and maybe other crashes.
I've added the required calls in the internal sources and it seems to work fine for me here.
However, I can't think on a workaround to make it work in current release so I'm afraid you'll have to wait for the next maintenance release (you can send mail to "info at steema dot com" asking for a test release).
UPDATE 2:
I initially modified the TeeChart sources to disable the Hardware Acceleration internally when a pen is set to DASH style. But setLayerType
was implemented in API 11 so, to keep TeeChart support from API 7, I had to remove it and let the developer to do this when necessary.