Android uses the Echarts frame of the candlestick chart

Source: Internet
Author: User

Baidu Echarts Framework is still relatively strong, before trying to use it, but after all, mainly used in Web page end, the effect is not very good, so eventually cancel the use of Echarts

But before the use of the process encountered some problems, although the solution is very simple, but also took me a lot of time, so here to record how to use and how to solve the problems encountered

1. Download demo on Echarts website

2, if the JS code is not very good to a function entry, then extract the package itself

(1) The function that has already extracted the package is unchanged

(2) The place where JS was first executed is extracted as a function, and the data variable of the graph is used as the parameter of the function.

(3) Put the HTML code in the assets directory of the Android project

(4) Android layout There is not much to write, directly add a webview on the line

(5) In Java code called JS, the code is as follows

//Set EncodingMwebview.getsettings (). Setdefaulttextencodingname ("Utf-8"); //Support JSMwebview.getsettings (). setjavascriptenabled (true); //Set Background color transparencyMwebview.setbackgroundcolor (Color.argb (0,0,0,0)); //Loading JS//mwebview.loadurl ("File:///android_asset/echarts-kline.html ");Mwebview.loadurl ("file:///android_asset/candlestick33.html"); Mwebview.loadurl ("javascript:jsfunction ('"+ jsparam+"')");

According to the previous format we call JS is no problem, but I am here the graph is unable to get to the data, so there is no graphics content

Think for a long time, with a lot of methods to try, the data is passed, but why not show it.

I also guess: is not the page graphics frame has been executed this code, and so on when the real graphics framework load needs to pass data, the data of the code is no longer called, but the Android side how to judge the page load well, this also depends on the speed of the bar

Then in a group a keen friend and I guessed together, but it knows if this is the reason, you can try what method, the method is as follows:

WebView can implement a onpagefinished method, as the name implies, when the page is loaded, we then go to invoke the JS function, here only the code that calls JS is placed in the following code

Mwebview.setwebviewclient (Newwebviewclient () {@Override Public voidonpagefinished (WebView view, String URL) { mwebview.loadurl ( "  javascript:jsfunction ('" + jsparam+ "')" );            super.onpagefinished (view, URL); } @Override PublicBoolean shouldoverrideurlloading (WebView view, String URL) {view.loadurl (URL); return true;    }        }); 

My writing is limited, there is a bad place to write please forgive me.

My Contact information:

more wonderful sharing, can follow my public number:

I'll take a tour. Scan the following QR code:

Number: Weixinjungle

Email: [Email protected]

Android uses the Echarts frame of the candlestick chart

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.