Echarts is an open-source, powerful data visualization product that follows the pace of the big Data era, I have been exposed to the best visual tools, but also the fastest-growing software, I hope it soon become a world-class open source projects, previously used Mpandroidchart,achartengine and other Android graphics icons, relatively echart style more, through the form of JS to achieve or the first time to see, say not much directly on the code
1. layout file Compare Simple timing 3 button, and one webview:
<relativelayout xmlns:android= "Http://schemas.android.com/apk/res/android"
Xmlns:tools= "Http://schemas.android.com/tools"
Android:layout_width= "Match_parent"
android:layout_height= "Match_parent"
android:paddingbottom= "@dimen/activity_vertical_margin"
android:paddingleft= "@dimen/activity_horizontal_margin"
android:paddingright= "@dimen/activity_horizontal_margin"
android:paddingtop= "@dimen/activity_vertical_margin"
tools:context= "Com.hzbst.echartst.MainActivity" >
<linearlayout
Android:id= "@+id/bt_ly"
Android:layout_width= "Match_parent"
android:layout_height= "Wrap_content"
Android:gravity= "Center_horizontal"
>
<button
Android:id= "@+id/linechart_bt"
Style= "? Android:attr/buttonstylesmall"
Android:layout_width= "Match_parent"
android:layout_height= "Wrap_content"
android:layout_weight= "1"
android:text= "Line chart"/>
<button
Android:id= "@+id/barchart_bt"
Style= "? Android:attr/buttonstylesmall"
Android:layout_width= "Match_parent"
android:layout_height= "Wrap_content"
android:layout_weight= "1"
android:text= "Histogram"/>
<button
Android:id= "@+id/piechart_bt"
Style= "? Android:attr/buttonstylesmall"
Android:layout_width= "Match_parent"
android:layout_height= "Wrap_content"
android:layout_weight= "1"
android:text= "pie chart"/>
</LinearLayout>
<webview
Android:id= "@+id/chartshow_wb"
Android:layout_width= "Match_parent"
android:layout_height= "Match_parent"
android:layout_alignright= "@+id/bt_ly"
android:layout_below= "@+id/bt_ly"
android:layout_margintop= "43DP"/>
</RelativeLayout>
2. Go to shelf echarts graphics in the code
Mainactivity class
Locate WebView, and then set some properties
chartshow_wb= (WebView) Findviewbyid (R.ID.CHARTSHOW_WB);
A bunch of settings for Webwiev
Open local file read (default is true, not set or YES)
Chartshow_wb.getsettings (). Setallowfileaccess (True);
Turn on scripting support
Chartshow_wb.getsettings (). Setjavascriptenabled (True);
Chartshow_wb.getsettings (). Setsupportzoom (True);
Chartshow_wb.getsettings (). Setbuiltinzoomcontrols (True);
Chartshow_wb.loadurl ("file:///android_asset/echart/myechart.html");
Loading via Loadurl, Myecharts file
Mycharts files are saved in the assets directory
Switch between different views with three buttons:
Line Graph Call: Chartshow_wb.loadurl ("Javascript:createchart" (' lines ', [29.2,29.2,29.2,29.2,29.2,29.1,29.1,], "+
"[' 2017-05-22 ', ' 2017-05-22 ', ' 2017-05-22 ', ' 2017-05-22 ', ' 2017-05-22 ', ' 2017-05-22 ', ' 2017-05-22 ',]); There are two parameters, which correspond to the x, y axes, respectively.
Two +:
Chartshow_wb.loadurl ("Javascript:createchart (' Bar ', [100,100,100]);");
Chartshow_wb.loadurl ("Javascript:createchart (' Pie", [100,100,100]);
That's it.
Source code: http://down.51cto.com/data/2309209
This article is from the Android Learning Notes blog, so be sure to keep this source http://846499695.blog.51cto.com/6937060/1929945
-echarts of Android Charts