Pre loader

VerticalLineAnnonation causes onMeasure() on SciChartSurface


I have created a SciChartSurface with a ColumnSeries. I update the series data every second with new values. I have turned on GPU profiling in Android developer options. After running the application I get the image shown in the attachment “SciChart_noCursor”. There are no new columns from the profiler drawn on each update of the chart’s data series. However when I add a VerticalLineAnnonation (which I use as a cursor) I get the image shown in the attachment “SciChart_withCursor”. On every update of the chart’s data series, the SciChartSurface is remeasured and redrawn and a lot of the frames take longer than 16.6 ms to redraw. I have also attached the source code of my example project.

My question is, is there a way to have a cursor line that won’t cause the whole surface to redraw on every update? In my production code I update the chart’s data 5 times per second and I have a much more complex layout. And causing layout measure on SciChartSurface is causing lots of janky frames. The reason I used a vertical line annotation as cursor is because I have have cursor info drawn outside of the SciChartSurface in my own TextView and with the built in cursor I wasn’t able to achieve that.

  • You must to post comments

Hi Miha,

I don’t think that it’s possible with current implementation of Annotations API. Current implementation updates annotation’s position on every chart redraw to ensure that it’s placed correctly. Theoretically we can skip some annotation updates if nothing changes but in case which you described (when you change data series which triggers redrawing of series ) you still need to redraw annotation because it’s drawn on top of series and after redrawing of series Android OS needs to draw annotation on top it.

Regarding profiling results – there are no columns in GPU profiler when you don’t use line annotation because by default chart is rendered on separate thread ( unless you use RenderSurface which uses Canvas to draw chart ) using OpenGL and built-in profiler can’t track this. However line annotation is another case. It’s View and when we change its position or content it schedules redrawing of entire application window because that how Android works.

Best regards,

  • MIha Rozina
    So the line annonation is a normal Android View, correct? And with each update of the series, you have to calculate it’s new position to correctly place it over the SciChartSurface? What I don’t understand is, why do you need to schedule to redraw of View’s that are outside of the SciChartSurface? With complex layouts that could be very expensive, yet there is no need to redraw anything outside of the SciChartSurface, because the surface’s size nor position changed. The annonation itself also cannot affect the surface’s position or size. Also in my case the annonation’s position only changes when the user taps the chart’s surface. Yet the annonation schedules a redraw on each update of data series (5 times per second in my case). Annonations seem to be very costly for a performance charting library.
  • Yura Khariton
    Yes, it’s a regular Android View. We use requestLayout() and invalidate() methods provided by View when we need to place or redraw annotation. Then it’s up to Android OS to decide which part of hierarchy should be remeasured/redrawn and there is nothing we can do here to limit it to only SciChartSurface.
  • You must to post comments
Showing 1 result
Your Answer

Please first to submit.

Try SciChart Today

Start a trial and discover why we are the choice
of demanding developers worldwide

Start TrialCase Studies