WilliamChart是基于Views的Android图表类库,帮助开发者在Android应用中实现折线图、柱状图和堆叠柱状图。数值发生变化时图表也会以动画的效果发生变化。
使用说明:
创建一个新的chart需要继承自ChartView的坐标轴,同时实现一些必要的方法。我觉的这些方法足以让你绘制出任何你想要的效果。
xml文件
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
|
<com.db.chart.view.ChartView 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" /> |
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
|
// 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(跟上面相同的部分用省略号)
|
1
2
3
|
<com.db.chart.LineChartView.../> |
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
|
LineChartView chartView= new LineChartView()LineSet lineSet = new LineSet()lineSet.addPoint(new Point(string, float)// Style dotslineSet.setDots(boolean)lineSet.setDotsColor(color)lineSet.setDotsRadius(dimen)lineSet.setDotsStrokeThickness(dimen)lineSet.setDotsStrokeColor(color)// Style linelineSet.setLineThickness(dimen)lineSet.setLineColor(color)// Style background filllineSet.setFill(boolean)lineSet.setFillColor(color)// Style typelineSet.setDashed(boolean)lineSet.setSmooth(boolean)chartView.addData(lineSet) |
BarChart & StackBarChart
|
1
2
3
4
5
|
<com.db.chart.BarChartView...chart:chart_barSpacing="dp"chart:chart_setSpacing="dp"/> |
java代码
|
1
2
3
4
5
6
7
8
9
10
11
|
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的设置
|
1
2
3
4
5
6
|
chart.setOnEntryClickListener(new OnEntryClickListener(){ @Override public void onClick(int setIndex, int entryIndex, Rect entryRect) { //Do things } }); |
动画
|
1
2
3
4
5
6
7
8
9
10
11
12
|
Animation anim = new Animation()anim.setDuration(integer)anim.setEasing(easingFunction)anim.setEndAction(runnable)// Animation overlap between entriesanim.setOverlap(float)// Animation starting pointanim.setStartPoint(float, float)// Include alpha transitionanim.setAlpha(int)// Starts animationchart.animate(animation) |
项目描述:Android library to create charts. — 查看更多内容...
| 问题列表: | ||
| #69 | Set Dots missing | 由 douglasd3 2015-08-19 |
| #61 | Not showing anything at all | 由 Ph1b 2015-08-16 |
| #50 | Can I set YAxis Label to right? | 由 xu6148152 2015-06-07 |
| #29 | Support CandleStickChart view | 由 Archinamon 2015-01-14 |
| #28 | Consider support for pie charts | 由 tuliohmendes 2015-07-29 |
原文:http://www.cnblogs.com/joey-hua/p/4741555.html