非常優秀開源圖表庫 HelloCharts
之前我們介紹了一個非常優秀開源圖表庫 MPAndroidChart ,但是我們今天介紹的將是一個更為優秀的圖表庫,比MPAndroidChart性能更好,功能更完善,UI風格更美觀,坐標軸更精細。
他就是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中定義:
<lecho.lib.hellocharts.view.LineChartView android:id="@+id/chart" android:layout_width="match_parent" android:layout_height="match_parent" />
當然也可以在java代碼中直接創建:
LineChartView chart = new LineChartView(context); layout.addView(chart);
可以通過一些公共方法設置其行為屬性,下面是一些例子:
Chart.setInteractive(boolean isInteractive); Chart.setZoomType(ZoomType zoomType); Chart.setContainerScrollEnabled(boolean isEnabled, ContainerScrollType type);
或者是用數據模型定義一些顯示的方式:
ChartData.setAxisXBottom(Axis axisX); ColumnChartData.setStacked(boolean isStacked); Line.setStrokeWidth(int strokeWidthDp);
每一種chart都有自己的數據模型以及設置數據的方法,下面以LineChart為例:
List<PointValue> values = new ArrayList<PointValue>(); values.add(new PointValue(0, 2)); values.add(new PointValue(1, 4)); values.add(new PointValue(2, 3)); values.add(new PointValue(3, 4)); //In most cased you can call data model methods in builder-pattern-like manner. Line line = new Line(values).setColor(Color.Blue).setCubic(true); List<Line> lines = new ArrayList<Line>(); lines.add(line); LineChartData data = new LineChartData(); data.setLines(lines); LineChartView chart = new LineChartView(context); chart.setLineChartData(data);
代碼下載地址
http://jcodecraeer.com/a/opensource/2014/1107/1931.html