android开发中怎么在界面上实现曲线图
推荐你几个相关开源项目,可以根据需要自己选择,自己画还是比较麻烦的:
-
MPAndroidChart
强大的图表绘制工具,支持折线图、面积图、散点图、时间图、柱状图、条图、饼图、气泡图、圆环图、范围(高至低)条形图、网状图及各种图的结合;支持图的拖拽缩放;支持 Android 2.2 以上,支持横纵轴缩放,多指缩放,展现动画、高亮、保存到 sdcard、从文件读取图表
-
achartengine
强大的图表绘制工具,支持折线图、面积图、散点图、时间图、柱状图、条图、饼图、气泡图、圆环图、范围(高至低)条形图、拨号图/表、立方线图及各种图的结合
-
GraphView
绘制图表和曲线图的View,可用于Android上的曲形图、柱状图、波浪图展示
-
HoloGraphLibrary
绘制线状图、柱状图、饼状图
-
XCL-Charts
XCL-Charts基于原生的Canvas来绘制各种图表,在设计时,尽量在保证开发效率的同时,给使用者提供足够多的定制化能力。因此使用简便,同时具有相当灵活的定制能力。目前支持3D/非3D柱形图(Bar Chart)、3D/非3D饼图(Pie Chart)、堆积图(Stacked Bar Chart)、面积图(Area Chart)、 折线图(Line Chart)、曲线图(Spline Chart)、环形图(Dount Chart)、南丁格尔玫瑰图(Rose Chart)、仪表盘(Dial Chart)、刻度盘(Gauge Chart)、雷达图(Radar Chart)、圆形图(Circle Chart)等图表。其它特性还包括支持图表缩放、手势移动、动画显示效果、高密度柱形显示、图表分界定制线、多图表的混合显示及同数据源不同类型图表切换等。
-
EazeGraph
Android 图表库,支持柱状图、分层柱状图、饼状图、线性图
-
WilliamChart
绘制图表的库,支持LineChartView、BarChartView和StackBarChartView三中图表类型,并且支持 Android 2.2及以上的系统。
-
HelloCharts for Android
支持折线图、柱状图、饼图、气泡图、组合图;支持预览、放大缩小,滚动,部分图表支持动画;支持 Android 2.2 以上
这些项目都可以在GitHub 搜索到。
==========================================================
hellocharts-android开源图表库(效果非常好)
就是github上出现的新项目HelloCharts。
HelloCharts支持以下chart类型:
-
Line chart(cubic lines, filled lines, scattered points)
Column chart(grouped, stacked, negative values)
Pie chart
Bubble chart
Combo chart(columns/lines)
-
Preview charts(for column chart and line chart)
此外还具有以下特点:
支持缩放、滑动以及平移。Zoom(pinch to zoom, double tap zoom), scroll and fling
支持自定义坐标轴(比如坐标轴位置:上下左右内部),支持自动生成坐标轴。Custom and auto-generated axes(top, bottom, left, right, inside)
动画(Animations)
支持预览,即在chart下面会有一个坐标密度更细的附属chart,当选中附属chart的某一区域,附属chart上面的chart会显示选中区域的更详细情况。
下面是一些效果截图:
我能用妙趣横生来形容吗、、
编译以及使用方法
每一种chart都可以在xml中定义:
[js] view plain copy- <ol class="linenums" style="border:0px; margin:0px 0px 10px 25px; padding:0px; color:rgb(204,204,204)"><li class="L0" style="border:0px; margin:0px; padding:0px 0px 0px 1em; list-style:decimal"><span class="tag" style="border:0px; margin:0px 4px; padding:1px 3px; color:navy; font-size:12px"><lecho.lib.hellocharts.view.LineChartView</span></li><li class="L1" style="border:0px; margin:0px; padding:0px 0px 0px 1em; list-style:decimal"><span class="pln" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)"> </span><span class="atn" style="border:0px; margin:0px; padding:0px; color:rgb(121,93,163)">android:id</span><span class="pun" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)">=</span><span class="atv" style="border:0px; margin:0px; padding:0px; color:rgb(24,54,145)">"@+id/chart"</span></li><li class="L2" style="border:0px; margin:0px; padding:0px 0px 0px 1em; list-style:decimal"><span class="pln" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)"> </span><span class="atn" style="border:0px; margin:0px; padding:0px; color:rgb(121,93,163)">android:layout_width</span><span class="pun" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)">=</span><span class="atv" style="border:0px; margin:0px; padding:0px; color:rgb(24,54,145)">"match_parent"</span></li><li class="L3" style="border:0px; margin:0px; padding:0px 0px 0px 1em; list-style:decimal"><span class="pln" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)"> </span><span class="atn" style="border:0px; margin:0px; padding:0px; color:rgb(121,93,163)">android:layout_height</span><span class="pun" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)">=</span><span class="atv" style="border:0px; margin:0px; padding:0px; color:rgb(24,54,145)">"match_parent"</span><span class="pln" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)"> </span><span class="tag" style="border:0px; margin:0px 4px; padding:1px 3px; color:navy; font-size:12px">/></span></li></ol>
当然也可以在Java代码中直接创建:
[js] view plain copy- <ol class="linenums" style="border:0px; margin:0px 0px 10px 25px; padding:0px; color:rgb(204,204,204)"><li class="L0" style="border:0px; margin:0px; padding:0px 0px 0px 1em; list-style:decimal"><span class="typ" style="border:0px; margin:0px; padding:0px; color:rgb(0,134,179)">LineChartView</span><span class="pln" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)"> chart </span><span class="pun" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)">=</span><span class="pln" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)"> </span><span class="kwd" style="border:0px; margin:0px; padding:0px; color:rgb(167,29,93)">new</span><span class="pln" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)"> </span><span class="typ" style="border:0px; margin:0px; padding:0px; color:rgb(0,134,179)">LineChartView</span><span class="pun" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)">(</span><span class="pln" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)">context</span><span class="pun" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)">);</span></li><li class="L1" style="border:0px; margin:0px; padding:0px 0px 0px 1em; list-style:decimal"><span class="pln" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)">layout</span><span class="pun" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)">.</span><span class="pln" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)">addView</span><span class="pun" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)">(</span><span class="pln" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)">chart</span><span class="pun" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)">);</span></li></ol>
可以通过一些公共方法设置其行为属性,下面是一些例子:
[js] view plain copy- <ol class="linenums" style="border:0px; margin:0px 0px 10px 25px; padding:0px; color:rgb(204,204,204)"><li class="L0" style="border:0px; margin:0px; padding:0px 0px 0px 1em; list-style:decimal"><span class="typ" style="border:0px; margin:0px; padding:0px; color:rgb(0,134,179)">Chart</span><span class="pun" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)">.</span><span class="pln" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)">setInteractive</span><span class="pun" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)">(</span><span class="kwd" style="border:0px; margin:0px; padding:0px; color:rgb(167,29,93)">boolean</span><span class="pln" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)"> isInteractive</span><span class="pun" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)">);</span></li><li class="L1" style="border:0px; margin:0px; padding:0px 0px 0px 1em; list-style:decimal"><span class="typ" style="border:0px; margin:0px; padding:0px; color:rgb(0,134,179)">Chart</span><span class="pun" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)">.</span><span class="pln" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)">setZoomType</span><span class="pun" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)">(</span><span class="typ" style="border:0px; margin:0px; padding:0px; color:rgb(0,134,179)">ZoomType</span><span class="pln" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)"> zoomType</span><span class="pun" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)">);</span></li><li class="L2" style="border:0px; margin:0px; padding:0px 0px 0px 1em; list-style:decimal"><span class="typ" style="border:0px; margin:0px; padding:0px; color:rgb(0,134,179)">Chart</span><span class="pun" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)">.</span><span class="pln" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)">setContainerScrollEnabled</span><span class="pun" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)">(</span><span class="kwd" style="border:0px; margin:0px; padding:0px; color:rgb(167,29,93)">boolean</span><span class="pln" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)"> isEnabled</span><span class="pun" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)">,</span><span class="pln" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)"> </span><span class="typ" style="border:0px; margin:0px; padding:0px; color:rgb(0,134,179)">ContainerScrollType</span><span class="pln" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)"> type</span><span class="pun" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)">);</span></li></ol>
或者是用数据模型定义一些显示的方式:
[js] view plain copy- <ol class="linenums" style="border:0px; margin:0px 0px 10px 25px; padding:0px; color:rgb(204,204,204)"><li class="L0" style="border:0px; margin:0px; padding:0px 0px 0px 1em; list-style:decimal"><span class="typ" style="border:0px; margin:0px; padding:0px; color:rgb(0,134,179)">ChartData</span><span class="pun" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)">.</span><span class="pln" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)">setAxisXBottom</span><span class="pun" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)">(</span><span class="typ" style="border:0px; margin:0px; padding:0px; color:rgb(0,134,179)">Axis</span><span class="pln" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)"> axisX</span><span class="pun" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)">);</span></li><li class="L1" style="border:0px; margin:0px; padding:0px 0px 0px 1em; list-style:decimal"><span class="typ" style="border:0px; margin:0px; padding:0px; color:rgb(0,134,179)">ColumnChartData</span><span class="pun" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)">.</span><span class="pln" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)">setStacked</span><span class="pun" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)">(</span><span class="kwd" style="border:0px; margin:0px; padding:0px; color:rgb(167,29,93)">boolean</span><span class="pln" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)"> isStacked</span><span class="pun" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)">);</span></li><li class="L2" style="border:0px; margin:0px; padding:0px 0px 0px 1em; list-style:decimal"><span class="typ" style="border:0px; margin:0px; padding:0px; color:rgb(0,134,179)">Line</span><span class="pun" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)">.</span><span class="pln" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)">setStrokeWidth</span><span class="pun" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)">(</span><span class="kwd" style="border:0px; margin:0px; padding:0px; color:rgb(167,29,93)">int</span><span class="pln" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)"> strokeWidthDp</span><span class="pun" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)">);</span></li></ol>
每一种chart都有自己的数据模型以及设置数据的方法,下面以LineChart为例:
[js] view plain copy- <ol class="linenums" style="border:0px; margin:0px 0px 10px 25px; padding:0px; color:rgb(204,204,204)"><li class="L0" style="border:0px; margin:0px; padding:0px 0px 0px 1em; list-style:decimal"><span class="typ" style="border:0px; margin:0px; padding:0px; color:rgb(0,134,179)">List</span><span class="pun" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)"><</span><span class="typ" style="border:0px; margin:0px; padding:0px; color:rgb(0,134,179)">PointValue</span><span class="pun" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)">></span><span class="pln" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)"> values </span><span class="pun" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)">=</span><span class="pln" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)"> </span><span class="kwd" style="border:0px; margin:0px; padding:0px; color:rgb(167,29,93)">new</span><span class="pln" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)"> </span><span class="typ" style="border:0px; margin:0px; padding:0px; color:rgb(0,134,179)">ArrayList</span><span class="pun" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)"><</span><span class="typ" style="border:0px; margin:0px; padding:0px; color:rgb(0,134,179)">PointValue</span><span class="pun" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)">>();</span></li><li class="L1" style="border:0px; margin:0px; padding:0px 0px 0px 1em; list-style:decimal"><span class="pln" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)">values</span><span class="pun" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)">.</span><span class="pln" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)">add</span><span class="pun" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)">(</span><span class="kwd" style="border:0px; margin:0px; padding:0px; color:rgb(167,29,93)">new</span><span class="pln" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)"> </span><span class="typ" style="border:0px; margin:0px; padding:0px; color:rgb(0,134,179)">PointValue</span><span class="pun" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)">(</span><span class="lit" style="border:0px; margin:0px; padding:0px; color:rgb(0,134,179)">0</span><span class="pun" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)">,</span><span class="pln" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)"> </span><span class="lit" style="border:0px; margin:0px; padding:0px; color:rgb(0,134,179)">2</span><span class="pun" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)">));</span></li><li class="L2" style="border:0px; margin:0px; padding:0px 0px 0px 1em; list-style:decimal"><span class="pln" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)">values</span><span class="pun" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)">.</span><span class="pln" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)">add</span><span class="pun" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)">(</span><span class="kwd" style="border:0px; margin:0px; padding:0px; color:rgb(167,29,93)">new</span><span class="pln" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)"> </span><span class="typ" style="border:0px; margin:0px; padding:0px; color:rgb(0,134,179)">PointValue</span><span class="pun" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)">(</span><span class="lit" style="border:0px; margin:0px; padding:0px; color:rgb(0,134,179)">1</span><span class="pun" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)">,</span><span class="pln" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)"> </span><span class="lit" style="border:0px; margin:0px; padding:0px; color:rgb(0,134,179)">4</span><span class="pun" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)">));</span></li><li class="L3" style="border:0px; margin:0px; padding:0px 0px 0px 1em; list-style:decimal"><span class="pln" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)">values</span><span class="pun" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)">.</span><span class="pln" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)">add</span><span class="pun" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)">(</span><span class="kwd" style="border:0px; margin:0px; padding:0px; color:rgb(167,29,93)">new</span><span class="pln" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)"> </span><span class="typ" style="border:0px; margin:0px; padding:0px; color:rgb(0,134,179)">PointValue</span><span class="pun" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)">(</span><span class="lit" style="border:0px; margin:0px; padding:0px; color:rgb(0,134,179)">2</span><span class="pun" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)">,</span><span class="pln" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)"> </span><span class="lit" style="border:0px; margin:0px; padding:0px; color:rgb(0,134,179)">3</span><span class="pun" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)">));</span></li><li class="L4" style="border:0px; margin:0px; padding:0px 0px 0px 1em; list-style:decimal"><span class="pln" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)">values</span><span class="pun" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)">.</span><span class="pln" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)">add</span><span class="pun" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)">(</span><span class="kwd" style="border:0px; margin:0px; padding:0px; color:rgb(167,29,93)">new</span><span class="pln" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)"> </span><span class="typ" style="border:0px; margin:0px; padding:0px; color:rgb(0,134,179)">PointValue</span><span class="pun" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)">(</span><span class="lit" style="border:0px; margin:0px; padding:0px; color:rgb(0,134,179)">3</span><span class="pun" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)">,</span><span class="pln" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)"> </span><span class="lit" style="border:0px; margin:0px; padding:0px; color:rgb(0,134,179)">4</span><span class="pun" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)">));</span></li><li class="L5" style="border:0px; margin:0px; padding:0px 0px 0px 1em; list-style:decimal"><span class="com" style="border:0px; margin:0px; padding:0px; color:rgb(150,152,150)">//In most cased you can call data model methods in builder-pattern-like manner.</span></li><li class="L6" style="border:0px; margin:0px; padding:0px 0px 0px 1em; list-style:decimal"><span class="typ" style="border:0px; margin:0px; padding:0px; color:rgb(0,134,179)">Line</span><span class="pln" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)"> line </span><span class="pun" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)">=</span><span class="pln" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)"> </span><span class="kwd" style="border:0px; margin:0px; padding:0px; color:rgb(167,29,93)">new</span><span class="pln" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)"> </span><span class="typ" style="border:0px; margin:0px; padding:0px; color:rgb(0,134,179)">Line</span><span class="pun" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)">(</span><span class="pln" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)">values</span><span class="pun" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)">).</span><span class="pln" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)">setColor</span><span class="pun" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)">(</span><span class="typ" style="border:0px; margin:0px; padding:0px; color:rgb(0,134,179)">Color</span><span class="pun" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)">.</span><span class="typ" style="border:0px; margin:0px; padding:0px; color:rgb(0,134,179)">Blue</span><span class="pun" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)">).</span><span class="pln" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)">setCubic</span><span class="pun" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)">(</span><span class="kwd" style="border:0px; margin:0px; padding:0px; color:rgb(167,29,93)">true</span><span class="pun" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)">);</span></li><li class="L7" style="border:0px; margin:0px; padding:0px 0px 0px 1em; list-style:decimal"><span class="typ" style="border:0px; margin:0px; padding:0px; color:rgb(0,134,179)">List</span><span class="pun" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)"><</span><span class="typ" style="border:0px; margin:0px; padding:0px; color:rgb(0,134,179)">Line</span><span class="pun" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)">></span><span class="pln" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)"> lines </span><span class="pun" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)">=</span><span class="pln" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)"> </span><span class="kwd" style="border:0px; margin:0px; padding:0px; color:rgb(167,29,93)">new</span><span class="pln" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)"> </span><span class="typ" style="border:0px; margin:0px; padding:0px; color:rgb(0,134,179)">ArrayList</span><span class="pun" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)"><</span><span class="typ" style="border:0px; margin:0px; padding:0px; color:rgb(0,134,179)">Line</span><span class="pun" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)">>();</span></li><li class="L8" style="border:0px; margin:0px; padding:0px 0px 0px 1em; list-style:decimal"><span class="pln" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)">lines</span><span class="pun" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)">.</span><span class="pln" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)">add</span><span class="pun" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)">(</span><span class="pln" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)">line</span><span class="pun" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)">);</span></li><li class="L9" style="border:0px; margin:0px; padding:0px 0px 0px 1em; list-style:decimal"><span class="typ" style="border:0px; margin:0px; padding:0px; color:rgb(0,134,179)">LineChartData</span><span class="pln" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)"> data </span><span class="pun" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)">=</span><span class="pln" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)"> </span><span class="kwd" style="border:0px; margin:0px; padding:0px; color:rgb(167,29,93)">new</span><span class="pln" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)"> </span><span class="typ" style="border:0px; margin:0px; padding:0px; color:rgb(0,134,179)">LineChartData</span><span class="pun" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)">();</span></li><li class="L0" style="border:0px; margin:0px; padding:0px 0px 0px 1em; list-style:decimal"><span class="pln" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)">data</span><span class="pun" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)">.</span><span class="pln" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)">setLines</span><span class="pun" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)">(</span><span class="pln" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)">lines</span><span class="pun" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)">);</span></li><li class="L1" style="border:0px; margin:0px; padding:0px 0px 0px 1em; list-style:decimal"><span class="typ" style="border:0px; margin:0px; padding:0px; color:rgb(0,134,179)">LineChartView</span><span class="pln" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)"> chart </span><span class="pun" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)">=</span><span class="pln" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)"> </span><span class="kwd" style="border:0px; margin:0px; padding:0px; color:rgb(167,29,93)">new</span><span class="pln" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)"> </span><span class="typ" style="border:0px; margin:0px; padding:0px; color:rgb(0,134,179)">LineChartView</span><span class="pun" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)">(</span><span class="pln" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)">context</span><span class="pun" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)">);</span></li><li class="L2" style="border:0px; margin:0px; padding:0px 0px 0px 1em; list-style:decimal"><span class="pln" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)">chart</span><span class="pun" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)">.</span><span class="pln" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)">setLineChartData</span><span class="pun" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)">(</span><span class="pln" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)">data</span><span class="pun" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)">);</span></li></ol>
代码下载地址
http://jcodecraeer.com/a/opensource/2014/1107/1931.html
==========================WilliamChart图表库
WilliamChart 是一个为安卓项目提供图表控件的开源库,他实现了数字的可视化,用作者的话说“我者喜欢看起来干净简单的图表,不想要那么多花哨的功能”。代码下载点这里:http://jcodecraeer.com/a/opensource/2014/1011/1738.html
运行效果:
使用说明:
创建一个新的chart需要继承自ChartView的坐标轴,同时实现一些必要的方法。我觉的这些方法足以让你绘制出任何你想要的效果。
xml
12345678910111213141516171819 | <com.db.chart.view.ChartView
xmlns:chart= "http://schemas.android.com/apk/res-auto"
android:layout_width= "match_parent"
android:layout_height= "dp"
...
chart:chart_shadowDx= "dp"
chart:chart_shadowDy= "dp"
chart:chart_shadowRadius= "dp"
chart:chart_shadowColor= "color"
chart:chart_fontSize= "dp"
chart:chart_typeface= "typeface"
chart:chart_axisBorderSpacing= "dp"
chart:chart_axisThickness= "dp"
chart:chart_axisTopSpacing= "dp"
chart:chart_axisColor= "color"
chart:chart_axisX= "boolean"
chart:chart_label= "boolean"
chart:chart_labelColor= "color"
/> |
--
123456789101112131415161718192021222324 | // Customize labels
chart.setLabels(NONE/OUTSIDE/INSIDE)
chart.setLabelColor(color)
chart.setFontSize(integer)
chart.setTypeface(typeface)
// Define grid
chart.setGrid(paint)
chart.setHorizontalGrid(paint)
chart.setVerticalGrid(paint)
// Show threshold line
chart.setThresholdLine(float, paint)
chart.setMaxAxisValue(integer, integer)
chart.setStep(integer)
chart.setTopSpacing(dimen)
chart.setBorderSpacing(dimen)
chart.setAxisX(boolean)
chart.show()
// Update values of a given set
chart.updateValues(int, array)
// Notify chart about updated values
chart.notifyDataUpdate()
// Tooltip support
chart.showTooltip(view)
chart.dismissTooltip(view) |
LineChart(跟上面相同的部分用省略号)
123 | <com.db.chart.LineChartView
...
/> |
java代码:
12345678910111213141516171819 | LineChartView chartView= new LineChartView() LineSet lineSet = new LineSet() lineSet.addPoint( new Point(string, float) // Style dots lineSet.setDots(boolean) lineSet.setDotsColor(color) lineSet.setDotsRadius(dimen) lineSet.setDotsStrokeThickness(dimen) lineSet.setDotsStrokeColor(color) // Style line lineSet.setLineThickness(dimen) lineSet.setLineColor(color) // Style background fill lineSet.setFill(boolean) lineSet.setFillColor(color) // Style type lineSet.setDashed(boolean) lineSet.setSmooth(boolean) chartView.addData(lineSet) |
BarChart & StackBarChart
12345 | <com.db.chart.BarChartView
...
chart:chart_barSpacing= "dp"
chart:chart_setSpacing= "dp"
/> |
java代码
1234567891011 | BarChartView chartView = new BarcChartView()
barChart.setBarSpacing(dimen)
barChart.setSetSpacing(dimen)
barChart.setBarBackground(boolean)
barChart.setBarBackgroundColor(color)
barChart.setRoundCorners(dimen)
BarSet barSet = new BarSet()
Bar bar = new Bar(string, float)
bar.setColor(color)
barSet.addBar(bar)
chartView.addData(barSet) |
Listener的设置
123456 | chart.setOnEntryClickListener( new OnEntryClickListener(){
@Override
public void onClick(int setIndex, int entryIndex, Rect entryRect) {
//Do things
}
}); |
动画
123456789101112 | Animation anim = new Animation() anim.setDuration(integer) anim.setEasing(easingFunction) anim.setEndAction(runnable) // Animation overlap between entries anim.setOverlap(float) // Animation starting point anim.setStartPoint(float, float) // Include alpha transition anim.setAlpha(int) // Starts animation chart.animate(animation) |
实现BaseEasingMethod
接口你可以自定义你自己的动画函数我已经实现了一些:
LinearEase
BounceEaseOut
ElasticEaseOut
CircEaseOut
CubicEaseOut
ExpoEaseOut
QuadEaseOut
QuartEaseOut
QuintEaseOut
SineEaseOut
android开源图表库MPAndroidChart(曲线图、直方图、饼状图)
该库的可扩展性强,代码相对规范,最近一次更新有很大改进,如果不喜欢AChartEngine的过于复杂可以考虑在此库的基础上开发自己的图表类。
linechart
填充式lineChart
单条线的LineChart
BarChart2D
BarChart3D
PieChart
ScatterChart
以piechart为例介绍使用方法:
xml中
[js] view plain copy
- <ol class="linenums" style="border:0px; margin:0px 0px 10px 25px; padding:0px; color:rgb(204,204,204)"><li class="L0" style="border:0px; margin:0px; padding:0px 0px 0px 1em; list-style:decimal"><span class="tag" style="border:0px; margin:0px 4px; padding:1px 3px; color:navy; font-size:12px"><com.github.mikephil.charting.charts.PieChart</span></li><li class="L1" style="border:0px; margin:0px; padding:0px 0px 0px 1em; list-style:decimal"><span class="pln" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)"> </span><span class="atn" style="border:0px; margin:0px; padding:0px; color:rgb(121,93,163)">android:id</span><span class="pun" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)">=</span><span class="atv" style="border:0px; margin:0px; padding:0px; color:rgb(24,54,145)">"@+id/spread_pie_chart"</span></li><li class="L2" style="border:0px; margin:0px; padding:0px 0px 0px 1em; list-style:decimal"><span class="pln" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)"> </span><span class="atn" style="border:0px; margin:0px; padding:0px; color:rgb(121,93,163)">android:layout_width</span><span class="pun" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)">=</span><span class="atv" style="border:0px; margin:0px; padding:0px; color:rgb(24,54,145)">"match_parent"</span></li><li class="L3" style="border:0px; margin:0px; padding:0px 0px 0px 1em; list-style:decimal"><span class="pln" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)"> </span><span class="atn" style="border:0px; margin:0px; padding:0px; color:rgb(121,93,163)">android:layout_height</span><span class="pun" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)">=</span><span class="atv" style="border:0px; margin:0px; padding:0px; color:rgb(24,54,145)">"320dip"</span><span class="pln" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)"> </span><span class="tag" style="border:0px; margin:0px 4px; padding:1px 3px; color:navy; font-size:12px">/></span></li></ol>
activity中
初始化
- <ol class="linenums" style="border:0px; margin:0px 0px 10px 25px; padding:0px; color:rgb(204,204,204)"><li class="L0" style="border:0px; margin:0px; padding:0px 0px 0px 1em; list-style:decimal"><span class="typ" style="border:0px; margin:0px; padding:0px; color:rgb(0,134,179)">ColorTemplate</span><span class="pln" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)"> mCt</span><span class="pun" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)">;</span></li><li class="L1" style="border:0px; margin:0px; padding:0px 0px 0px 1em; list-style:decimal"><span class="pln" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)"> mCt </span><span class="pun" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)">=</span><span class="pln" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)"> </span><span class="kwd" style="border:0px; margin:0px; padding:0px; color:rgb(167,29,93)">new</span><span class="pln" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)"> </span><span class="typ" style="border:0px; margin:0px; padding:0px; color:rgb(0,134,179)">ColorTemplate</span><span class="pun" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)">();</span></li><li class="L2" style="border:0px; margin:0px; padding:0px 0px 0px 1em; list-style:decimal"><span class="pln" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)"> mCt</span><span class="pun" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)">.</span><span class="pln" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)">addDataSetColors</span><span class="pun" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)">(</span><span class="typ" style="border:0px; margin:0px; padding:0px; color:rgb(0,134,179)">ColorTemplate</span><span class="pun" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)">.</span><span class="pln" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)">PASTEL_COLORS</span><span class="pun" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)">,</span><span class="pln" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)"> </span><span class="kwd" style="border:0px; margin:0px; padding:0px; color:rgb(167,29,93)">this</span><span class="pun" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)">);</span></li><li class="L3" style="border:0px; margin:0px; padding:0px 0px 0px 1em; list-style:decimal"><span class="pln" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)"> mChart </span><span class="pun" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)">=</span><span class="pln" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)"> </span><span class="pun" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)">(</span><span class="typ" style="border:0px; margin:0px; padding:0px; color:rgb(0,134,179)">PieChart</span><span class="pun" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)">)</span><span class="pln" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)"> headView</span><span class="pun" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)">.</span><span class="pln" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)">findViewById</span><span class="pun" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)">(</span><span class="pln" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)">R</span><span class="pun" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)">.</span><span class="pln" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)">id</span><span class="pun" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)">.</span><span class="pln" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)">spread_pie_chart</span><span class="pun" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)">);</span></li><li class="L4" style="border:0px; margin:0px; padding:0px 0px 0px 1em; list-style:decimal"><span class="pln" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)"> mChart</span><span class="pun" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)">.</span><span class="pln" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)">setColorTemplate</span><span class="pun" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)">(</span><span class="pln" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)">mCt</span><span class="pun" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)">);</span></li><li class="L5" style="border:0px; margin:0px; padding:0px 0px 0px 1em; list-style:decimal"><span class="pln" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)"> mChart</span><span class="pun" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)">.</span><span class="pln" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)">setDescription</span><span class="pun" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)">(</span><span class="str" style="border:0px; margin:0px; padding:0px; color:rgb(24,54,145)">""</span><span class="pun" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)">);</span></li><li class="L6" style="border:0px; margin:0px; padding:0px 0px 0px 1em; list-style:decimal"><span class="pln" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)"> mChart</span><span class="pun" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)">.</span><span class="pln" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)">setHoleRadius</span><span class="pun" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)">(</span><span class="lit" style="border:0px; margin:0px; padding:0px; color:rgb(0,134,179)">30f</span><span class="pun" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)">);</span></li><li class="L7" style="border:0px; margin:0px; padding:0px 0px 0px 1em; list-style:decimal"><span class="pln" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)"> mChart</span><span class="pun" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)">.</span><span class="pln" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)">setTransparentCircleRadius</span><span class="pun" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)">(</span><span class="lit" style="border:0px; margin:0px; padding:0px; color:rgb(0,134,179)">0f</span><span class="pun" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)">);</span></li><li class="L8" style="border:0px; margin:0px; padding:0px 0px 0px 1em; list-style:decimal"><span class="pln" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)"> mChart</span><span class="pun" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)">.</span><span class="pln" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)">setCenterTextSize</span><span class="pun" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)">(</span><span class="lit" style="border:0px; margin:0px; padding:0px; color:rgb(0,134,179)">18f</span><span class="pun" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)">);</span></li><li class="L9" style="border:0px; margin:0px; padding:0px 0px 0px 1em; list-style:decimal"><span class="pln" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)"> mChart</span><span class="pun" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)">.</span><span class="pln" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)">setDrawXValues</span><span class="pun" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)">(</span><span class="kwd" style="border:0px; margin:0px; padding:0px; color:rgb(167,29,93)">true</span><span class="pun" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)">);</span></li><li class="L0" style="border:0px; margin:0px; padding:0px 0px 0px 1em; list-style:decimal"><span class="pln" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)"> mChart</span><span class="pun" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)">.</span><span class="pln" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)">setUsePercentValues</span><span class="pun" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)">(</span><span class="kwd" style="border:0px; margin:0px; padding:0px; color:rgb(167,29,93)">true</span><span class="pun" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)">);</span></li><li class="L1" style="border:0px; margin:0px; padding:0px 0px 0px 1em; list-style:decimal"><span class="pln" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)"> mChart</span><span class="pun" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)">.</span><span class="pln" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)">setDrawLegend</span><span class="pun" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)">(</span><span class="kwd" style="border:0px; margin:0px; padding:0px; color:rgb(167,29,93)">false</span><span class="pun" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)">);</span></li><li class="L2" style="border:0px; margin:0px; padding:0px 0px 0px 1em; list-style:decimal"><span class="pln" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)"> </span><span class="com" style="border:0px; margin:0px; padding:0px; color:rgb(150,152,150)">// space between slices</span></li><li class="L3" style="border:0px; margin:0px; padding:0px 0px 0px 1em; list-style:decimal"><span class="pln" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)"> mChart</span><span class="pun" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)">.</span><span class="pln" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)">setSliceSpace</span><span class="pun" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)">(</span><span class="lit" style="border:0px; margin:0px; padding:0px; color:rgb(0,134,179)">1f</span><span class="pun" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)">);</span></li><li class="L4" style="border:0px; margin:0px; padding:0px 0px 0px 1em; list-style:decimal"><span class="pln" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)"> mChart</span><span class="pun" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)">.</span><span class="pln" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)">setDrawHoleEnabled</span><span class="pun" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)">(</span><span class="kwd" style="border:0px; margin:0px; padding:0px; color:rgb(167,29,93)">false</span><span class="pun" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)">);</span></li><li class="L5" style="border:0px; margin:0px; padding:0px 0px 0px 1em; list-style:decimal"><span class="pln" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)"> mChart</span><span class="pun" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)">.</span><span class="pln" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)">setTouchEnabled</span><span class="pun" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)">(</span><span class="kwd" style="border:0px; margin:0px; padding:0px; color:rgb(167,29,93)">false</span><span class="pun" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)">);</span></li></ol>
数据
- <ol class="linenums" style="border:0px; margin:0px 0px 10px 25px; padding:0px; color:rgb(204,204,204)"><li class="L0" style="border:0px; margin:0px; padding:0px 0px 0px 1em; list-style:decimal"><span class="typ" style="border:0px; margin:0px; padding:0px; color:rgb(0,134,179)">ArrayList</span><span class="pun" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)"><</span><span class="typ" style="border:0px; margin:0px; padding:0px; color:rgb(0,134,179)">Entry</span><span class="pun" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)">></span><span class="pln" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)"> yVals </span><span class="pun" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)">=</span><span class="pln" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)"> </span><span class="kwd" style="border:0px; margin:0px; padding:0px; color:rgb(167,29,93)">new</span><span class="pln" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)"> </span><span class="typ" style="border:0px; margin:0px; padding:0px; color:rgb(0,134,179)">ArrayList</span><span class="pun" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)"><</span><span class="typ" style="border:0px; margin:0px; padding:0px; color:rgb(0,134,179)">Entry</span><span class="pun" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)">>();</span></li><li class="L1" style="border:0px; margin:0px; padding:0px 0px 0px 1em; list-style:decimal"><span class="typ" style="border:0px; margin:0px; padding:0px; color:rgb(0,134,179)">ArrayList</span><span class="pun" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)"><</span><span class="typ" style="border:0px; margin:0px; padding:0px; color:rgb(0,134,179)">String</span><span class="pun" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)">></span><span class="pln" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)"> xVals </span><span class="pun" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)">=</span><span class="pln" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)"> </span><span class="kwd" style="border:0px; margin:0px; padding:0px; color:rgb(167,29,93)">new</span><span class="pln" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)"> </span><span class="typ" style="border:0px; margin:0px; padding:0px; color:rgb(0,134,179)">ArrayList</span><span class="pun" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)"><</span><span class="typ" style="border:0px; margin:0px; padding:0px; color:rgb(0,134,179)">String</span><span class="pun" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)">>();</span></li><li class="L2" style="border:0px; margin:0px; padding:0px 0px 0px 1em; list-style:decimal"><span class="kwd" style="border:0px; margin:0px; padding:0px; color:rgb(167,29,93)">for</span><span class="pln" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)"> </span><span class="pun" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)">(</span><span class="kwd" style="border:0px; margin:0px; padding:0px; color:rgb(167,29,93)">int</span><span class="pln" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)"> i </span><span class="pun" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)">=</span><span class="pln" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)"> </span><span class="lit" style="border:0px; margin:0px; padding:0px; color:rgb(0,134,179)">0</span><span class="pun" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)">;</span><span class="pln" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)"> i </span><span class="pun" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)"><</span><span class="pln" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)"> listDatas</span><span class="pun" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)">.</span><span class="pln" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)">size</span><span class="pun" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)">();</span><span class="pln" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)"> i</span><span class="pun" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)">++)</span><span class="pln" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)"> </span><span class="pun" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)">{</span></li><li class="L3" style="border:0px; margin:0px; padding:0px 0px 0px 1em; list-style:decimal"><span class="pln" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)"> yVals</span><span class="pun" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)">.</span><span class="pln" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)">add</span><span class="pun" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)">(</span><span class="kwd" style="border:0px; margin:0px; padding:0px; color:rgb(167,29,93)">new</span><span class="pln" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)"> </span><span class="typ" style="border:0px; margin:0px; padding:0px; color:rgb(0,134,179)">Entry</span><span class="pun" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)">((</span><span class="kwd" style="border:0px; margin:0px; padding:0px; color:rgb(167,29,93)">float</span><span class="pun" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)">)</span><span class="pln" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)">listDatas</span><span class="pun" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)">.</span><span class="kwd" style="border:0px; margin:0px; padding:0px; color:rgb(167,29,93)">get</span><span class="pun" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)">(</span><span class="pln" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)">i</span><span class="pun" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)">).</span><span class="pln" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)">getProvinceCount</span><span class="pun" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)">(),</span><span class="pln" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)"> i</span><span class="pun" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)">));</span></li><li class="L4" style="border:0px; margin:0px; padding:0px 0px 0px 1em; list-style:decimal"><span class="pln" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)"> xVals</span><span class="pun" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)">.</span><span class="pln" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)">add</span><span class="pun" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)">(</span><span class="pln" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)">listDatas</span><span class="pun" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)">.</span><span class="kwd" style="border:0px; margin:0px; padding:0px; color:rgb(167,29,93)">get</span><span class="pun" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)">(</span><span class="pln" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)">i</span><span class="pun" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)">).</span><span class="pln" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)">getProvinceName</span><span class="pun" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)">());</span></li><li class="L5" style="border:0px; margin:0px; padding:0px 0px 0px 1em; list-style:decimal"><span class="pun" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)">}</span></li><li class="L6" style="border:0px; margin:0px; padding:0px 0px 0px 1em; list-style:decimal"><span class="typ" style="border:0px; margin:0px; padding:0px; color:rgb(0,134,179)">DataSet</span><span class="pln" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)"> set1 </span><span class="pun" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)">=</span><span class="pln" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)"> </span><span class="kwd" style="border:0px; margin:0px; padding:0px; color:rgb(167,29,93)">new</span><span class="pln" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)"> </span><span class="typ" style="border:0px; margin:0px; padding:0px; color:rgb(0,134,179)">DataSet</span><span class="pun" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)">(</span><span class="pln" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)">yVals</span><span class="pun" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)">,</span><span class="pln" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)"> </span><span class="str" style="border:0px; margin:0px; padding:0px; color:rgb(24,54,145)">"Content"</span><span class="pun" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)">);</span></li><li class="L7" style="border:0px; margin:0px; padding:0px 0px 0px 1em; list-style:decimal"><span class="typ" style="border:0px; margin:0px; padding:0px; color:rgb(0,134,179)">ArrayList</span><span class="pun" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)"><</span><span class="typ" style="border:0px; margin:0px; padding:0px; color:rgb(0,134,179)">DataSet</span><span class="pun" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)">></span><span class="pln" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)"> dataSets </span><span class="pun" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)">=</span><span class="pln" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)"> </span><span class="kwd" style="border:0px; margin:0px; padding:0px; color:rgb(167,29,93)">new</span><span class="pln" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)"> </span><span class="typ" style="border:0px; margin:0px; padding:0px; color:rgb(0,134,179)">ArrayList</span><span class="pun" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)"><</span><span class="typ" style="border:0px; margin:0px; padding:0px; color:rgb(0,134,179)">DataSet</span><span class="pun" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)">>();</span></li><li class="L8" style="border:0px; margin:0px; padding:0px 0px 0px 1em; list-style:decimal"><span class="pln" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)">dataSets</span><span class="pun" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)">.</span><span class="pln" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)">add</span><span class="pun" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)">(</span><span class="pln" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)">set1</span><span class="pun" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)">);</span></li><li class="L9" style="border:0px; margin:0px; padding:0px 0px 0px 1em; list-style:decimal"><span class="typ" style="border:0px; margin:0px; padding:0px; color:rgb(0,134,179)">ChartData</span><span class="pln" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)"> data </span><span class="pun" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)">=</span><span class="pln" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)"> </span><span class="kwd" style="border:0px; margin:0px; padding:0px; color:rgb(167,29,93)">new</span><span class="pln" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)"> </span><span class="typ" style="border:0px; margin:0px; padding:0px; color:rgb(0,134,179)">ChartData</span><span class="pun" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)">(</span><span class="pln" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)">xVals</span><span class="pun" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)">,</span><span class="pln" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)"> dataSets</span><span class="pun" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)">);</span></li><li class="L0" style="border:0px; margin:0px; padding:0px 0px 0px 1em; list-style:decimal"><span class="pln" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)">mChart</span><span class="pun" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)">.</span><span class="pln" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)">setData</span><span class="pun" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)">(</span><span class="pln" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)">data</span><span class="pun" style="border:0px; margin:0px; padding:0px; color:rgb(51,51,51)">);</span></li></ol>
其中listData为自己项目中的数据源。
项目地址:https://github.com/PhilJay/MPAndroidChart
注:关于图表库现在有了更好的项目hellocharts,见http://jcodecraeer.com/a/anzhuokaifa/androidkaifa/2014/1107/1930.html
From:http://blog.csdn.net/a2241076850/article/details/52413434