Pre loader

Trouble with chart visible/gone with MVVM architecture (does not always update visibility correctly)

Welcome to the SciChart Forums!

  • Please read our Question Asking Guidelines for how to format a good question
  • Some reputation is required to post answers. Get up-voted to avoid the spam filter!
  • We welcome community answers and upvotes. Every Q&A improves SciChart for everyone

WPF Forums | JavaScript Forums | Android Forums | iOS Forums

Answered
0
0

Hi,

I’m trying to write an app which dynamically hides/shows (Visible/Gone) scichart surface without losing the data rendering. I’ve been trying to drive this via android visiblity and observable fields (MVVM design). An example of how our surfaces look is as follows:

<com.scichart.charting.visuals.SciChartSurface
android:id=”@+id/temperature_chart”
android:layout_width=”match_parent”
android:layout_height=”0dp”
android:layout_weight=”.99″
android:visibility=”@{graphViewModel.displayChartTemp ? View.VISIBLE : View.GONE}”
android:paddingTop=”@dimen/potrero_gap”
android:paddingBottom=”@dimen/potrero_gap”
scichart:verticalGroup=”@{graphViewModel.sharedVG}”
scichart:renderableSeries=”@{graphViewModel.tempRenderableSeries}”
scichart:xAxes=”@{graphViewModel.xTempAxes}”
scichart:yAxes=”@{graphViewModel.yTempAxes}”/>

and in the view model:

declaration:
var displayChartTemp = ObservableBoolean()

and to set the visibility….
displayChartTemp.set(true)
displayChartTemp.set(false)

I saw that historically, one solution was to
rsiChart.setRenderSurface(null);
rsiChart.setRenderSurface(new RenderSurfaceGL(getActivity()));

but I was wondering if there would be a good way to do this with MVVM architecture, and drive it similarly with observables?

Thanks,
-Andy

Version
2.2.2.2424
  • You must to post comments
Best Answer
1
0

Hi Andrew,

I think you can do this by creating custom SciChartSurface and overriding it setVisibility() method with next code:

class CustomSciChartSurface extends SciChartSurface {

public CustomSciChartSurface(Context context) {
    super(context);
}

public CustomSciChartSurface(Context context, AttributeSet attrs) {
    super(context, attrs);
}

public CustomSciChartSurface(Context context, AttributeSet attrs, int defStyleAttr) {
    super(context, attrs, defStyleAttr);
}

@Override
public void setVisibility(int visibility) {
    super.setVisibility(visibility);

    switch (visibility) {

        case View.GONE:
            setRenderSurface(null);
            break;
        case View.INVISIBLE:
            break;
        case View.VISIBLE:
            setRenderSurface(new RenderSurfaceGL(getContext()));
            break;
    }
}

}

In this case you won’t need to do anything else except switching visibility.

Is this suitable for your needs?

Best regards,
Yura

  • Andrew Chin
    Hi Yura, That should work for us I think, thanks! -Andy
  • 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