Android图表之-Echarts

ECharts是一款开源、功能强大的数据可视化产品,紧跟着大数据时代的步伐,是我接触过的最优秀的可视化工具,也是进步最快的软件,希望它早日成为世界级的开源项目,之前使用过MPAndroidChart,achartengine 等android下的图形图标,相对而言Echart样式更多,通过JS的形式来实现还是第一次见 ,话不多说直接上代码 

成都创新互联成立于2013年,是专业互联网技术服务公司,拥有项目网站设计、网站制作网站策划,项目实施与项目整合能力。我们以让每一个梦想脱颖而出为使命,1280元华安做网站,已为上家服务,为华安各地企业和个人服务,联系电话:028-86922220

 

  1.布局文件比较简单定时3个Button ,和一个Webview :


  

    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" >

    android:id="@+id/bt_ly"

    android:layout_width="match_parent"

        android:layout_height="wrap_content"

        android:gravity="center_horizontal"

    >

    android:id="@+id/linechart_bt"

    

    android:layout_width="match_parent"

    android:layout_height="wrap_content"

    android:layout_weight="1"

    android:text="折线图" />

    

    android:id="@+id/barchart_bt"

    

    android:layout_width="match_parent"

    android:layout_height="wrap_content"

    android:layout_weight="1"

    android:text="柱状图" />

    android:id="@+id/piechart_bt"

    

    android:layout_width="match_parent"

    android:layout_height="wrap_content"

    android:layout_weight="1"

    android:text="饼状图" />


    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" />

    

2. 在代码中去架子Echarts图形

  MainActivity类 

找到Webview,然后设置一些属性

chartshow_wb=(WebView)findViewById(R.id.chartshow_wb);

//进行webwiev的一堆设置

//开启本地文件读取(默认为true,不设置也可以)

chartshow_wb.getSettings().setAllowFileAccess(true);

//开启脚本支持

chartshow_wb.getSettings().setJavaScriptEnabled(true);

chartshow_wb.getSettings().setSupportZoom(true);

chartshow_wb.getSettings().setBuiltInZoomControls(true);

chartshow_wb.loadUrl("file:///android_asset/echart/myechart.html");

通过loadUrl加载,myecharts文件

mycharts文件保存在assets目录下

通过三个按钮来切换不同的视图 :

折线图调用:chartshow_wb.loadUrl("javascript:createChart('line',[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',]);"); 上面有两个参数,分别为X,y轴对应的数据

其他两个 :

chartshow_wb.loadUrl("javascript:createChart('bar',[100,100,100]);");

chartshow_wb.loadUrl("javascript:createChart('pie",[100,100,100]);");

这样就可以了


源代码下载地址:http://down.51cto.com/data/2309209

附件:http://down.51cto.com/data/2366697

本文标题:Android图表之-Echarts
地址分享:http://lszwz.com/article/jiejgh.html

其他资讯

售后响应及时

7×24小时客服热线

数据备份

更安全、更高效、更稳定

价格公道精准

项目经理精准报价不弄虚作假

合作无风险

重合同讲信誉,无效全额退款