Andriod app – CardAdapter calls API that returns JSON data for trading chart, fails to display using webView

would anyone able to help me to resolve the issue in my Android app as I am new to develop Android mobile app.

I have a website, using python/flask, to display trading chart. the javascript from within the HTML page calls python API to return JSON data for display trading chart. It works well.

In my Android program, my cardAdaptor call the same Python API, but i do not know how to make it work in webView.

I show you my codes for the web first, hopefully you can understand what my issue
my python API code:

import yfinance as yf
import json
import plotly.express as px
import plotly

st = yf.Ticker("ANZ.AX")
df = st.history(period="1d", interval="1m")
df=df.reset_index()
df.columns = ['Date-Time']+list(df.columns[1:])
max = (df['Open'].max())
min = (df['Open'].min())
range = max - min
margin = range * 0.05
max = max + margin
min = min - margin
fig = px.area(df, x="Date-Time", y="Open",
    width=850, height=450,
        hover_data=("Open","Close","Volume"),
        range_y=(min,max), template="seaborn" )
fig.update_layout(title_text="ANZ Group", title_x=0.5)
#fig.show()
graphJSON = json.dumps(fig, cls=plotly.utils.PlotlyJSONEncoder)
return graphJSON

In html code:

<script src="https://cdn.plot.ly/plotly-latest.min.js"></script>
<script src="/static/assets/plugins/chart.js/Chart.min.js"></script>
                  <script>
                  const [response,
                        dailyTradeResponse
                         ] = await Promise.all([
                      fetch("/callback/getStock?data=" + Stock + "&period=" + Period + "&interval=" + Interval + "&chartselected=" + Chartselected),
                      fetch("/callback/getDailyTradeInfo?data=" + Stock + "&period=" + Period + "&interval=" + Interval )

                  ]);
                  response = fetch("/callback/getStock?data=" + Stock + "&period=" + Period + "&interval=" + Interval + "&chartselected=" + Chartselected)
                  if (response.ok) {
                      var chartJson = await response.json();
                      if (response.ok) {
                          Plotly.newPlot('chart', chartJson, {});
                          //hideSpinnerAndDisplayChartBlock();
                      } 
                  }
                  </script>


     div class="card-body">
         <div id="chart" class="chart"></div>
     </div>

I want to do the same thing in my Android App. that is what i have done.
first. i set up the permission from the AndroidMainfest.xml

 <uses-permission android:name="android.permission.INTERNET" />

Create a cardView trading layout, card_trading_chart.xml

<androidx.cardview.widget.CardView
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:padding="8dp">

    <!-- Other views (if needed) -->

    <WebView
        android:id="@+id/tradingChartWebView"
        android:layout_width="match_parent"
        android:layout_height="200dp"
        tools:ignore="WebViewLayout" />
</androidx.cardview.widget.CardView>

In my Java CardAdapter, call the api and place the output to webView

// CardAdapter.java
public class CardAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
    private static  int TYPE_IMAGE_TITLE = 0;
    private static  int TYPE_TRADING_CHART = 0;
    private List<CardItem> cardItems; // Your data model (list of items)
    private boolean isHorizontal; // Flag to determine the orientation

    public CardAdapter(List<CardItem> cardItems, boolean isHorizontal) {
        this.cardItems = cardItems;
        this.isHorizontal = isHorizontal;

        if (isHorizontal) {
            TYPE_TRADING_CHART = 0;
        } else {
            TYPE_TRADING_CHART = 1;
        }
    }

    @NonNull
    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        LayoutInflater inflater = LayoutInflater.from(parent.getContext());
        if (isHorizontal) {
            View itemView = inflater.inflate(R.layout.card_trading_chart, parent, false);
            return new TradingChartViewHolder(itemView);
        } else {
            View itemView = inflater.inflate(R.layout.card_item, parent, false);
            return new ImageTitleViewHolder(itemView);
        }

    }

    @Override
    public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) {
        System.out.println("position:[" + position + "]");
        CardItem item = cardItems.get(position);

        if (holder instanceof ImageTitleViewHolder) {
            // Bind data for image + title card
            ImageTitleViewHolder imageTitleHolder = (ImageTitleViewHolder) holder;
            imageTitleHolder.itemTitle.setText(item.getTitle());
            imageTitleHolder.itemImage.setImageResource(item.getImageResId());
            //Load image using Glide/Picasso or set drawable directly

        } else if (holder instanceof TradingChartViewHolder) {
            TradingChartViewHolder chartHolder = (TradingChartViewHolder) holder;

            // Load trading chart data into the WebView
            String chartUrl = "https://mytradingbot.com.au/apicallback/getRSIGaugeChart?data=ANZ.AX";
            chartHolder.tradingChartWebView.loadUrl(chartUrl);

        }
    }

    @Override
    public int getItemCount() {
        return cardItems.size();
    }

    // Custom view holder for image + title card
    static class ImageTitleViewHolder extends RecyclerView.ViewHolder {
        ImageView itemImage;
        TextView itemTitle;

        ImageTitleViewHolder(View itemView) {
            super(itemView);
            itemImage = itemView.findViewById(R.id.itemImage);
            itemTitle = itemView.findViewById(R.id.itemTitle);
        }
    }

    // Custom view holder for trading chart card
    static class TradingChartViewHolder extends RecyclerView.ViewHolder {
        WebView tradingChartWebView;

        @SuppressLint("SetJavaScriptEnabled")
        TradingChartViewHolder(View itemView) {
            super(itemView);
            tradingChartWebView = itemView.findViewById(R.id.tradingChartWebView);
            tradingChartWebView.getSettings().setJavaScriptEnabled(true);
        }
    }

}

when I run my android app, the webView only shows the JSON Data. See attached screen shot. I can understand why, cos in webView, i need to call

Plotly.newPlot('chart', chartJson, {});

Can anyone advise me? doesn’t have to do it in webView, i just want to display the trading char.enter image description here

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật