SciChart® the market leader in Fast WPF Charts, WPF 3D Charts, iOS Chart, Android Chart and JavaScript Chart Components
Quick example. All charts visible:
Setting Visibility.GONE to RSI chart:
As you can see part of RSI chart is now visible on MACD chart.
Here is my layout. I want to be able to hide any of the charts inside LinearLayout and the remaining charts should equally fill the newly created space. I wasn’t able to recreate the desired behaviour with ConstraintLayout, otherwise I would use it.
<com.scichart.charting.visuals.SciChartSurface
android:id="@+id/priceChart"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1" />
<LinearLayout
android:layout_width="match_parent"
android:orientation="vertical"
android:layout_height="0dp"
android:layout_weight="1">
<com.scichart.charting.visuals.SciChartSurface
android:id="@+id/macdChart"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"/>
<com.scichart.charting.visuals.SciChartSurface
android:id="@+id/rsiChart"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"/>
<com.scichart.charting.visuals.SciChartSurface
android:id="@+id/volumeChart"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"/>
</LinearLayout>
Hi there,
I believe this happens because our default RenderSurface implementation is based on GLSurfaceView which ignores visibility values because it draws its content outside of Android View hierarchy.
To workaround this issue you can:
set render surface to null when setting Visibility.GONE which will detach render surface from chart:
rsiChart.setVisibility(View.GONE);
rsiChart.setRenderSurface(null);
and when you need to make chart visible again you’ll need to assign render surface again:
rsiChart.setRenderSurface(new RenderSurfaceGL(getActivity()));
rsiChart.setVisibility(View.VISIBLE);
you can init chart after it is created with alternative render surface implementation which correctly handles visibility changes so you won’t need to set render surface when visibility changes:
// use alternative OpenGL based render surface
surface.setRenderSurface(new GLTextureView(getActivity()));
// or use Canvas based render surface
surface.setRenderSurface(new RenderSurface(getActivity()));
as alternative to previous approach you can create custom SciChartSurface class and override method which creates render surface which is used by default to render chart:
class CanvasSciChartSurface extends SciChartSurface {
public CanvasSciChartSurface(Context context) {
super(context);
}
public CanvasSciChartSurface(Context context, AttributeSet attrs) {
super(context, attrs);
}
public CanvasSciChartSurface(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
@Override
protected IRenderSurface getDefaultRenderSurface(Context context) {
return new RenderSurface(context); // return alternative render surface implementation here
}
}
Hope this will help you!
Best regards,
Yura
Please login first to submit.