安卓图表控件WilliamChart使用指南
来源:互联网 发布:代理淘宝开店 编辑:程序博客网 时间:2024/05/24 07:34
WilliamChart是github上的一个android图表控件,项目地址:https://github.com/diogobernardino/WilliamChart
该图表控件效果不错,使用也比较方便。
参考它提供的示例程序,我写了一个更加简单的图表程序,步骤如下:
1.从github上下载项目,将其library项目导入adt;
2.将其sample项目导入adt;
3.创建自己的工程,引用library项目,并将sample项目中的DataRetriever类拷贝到本项目的源代码目录中;
4.创建一个chart_layout.xml代码如下:
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <com.db.chart.view.LineChartViewxmlns:chart="http://schemas.android.com/apk/res-auto"android:id="@+id/linechart" android:layout_width="match_parent" android:layout_height="0dp" android:layout_weight=".30" android:paddingTop="15dp" android:paddingBottom="5dp" android:paddingLeft="10dp" android:paddingRight="10dp" chart:chart_shadowDy="1dp" chart:chart_shadowRadius="1dp" chart:chart_shadowColor="#80000000" chart:chart_axisColor="@color/axis" chart:chart_axisBorderSpacing="0dp"></com.db.chart.view.LineChartView></LinearLayout>
5.创建一个Activity类,代码如下:
package com.example.wxb_example;import com.db.chart.model.LineSet;import com.db.chart.model.Point;import com.db.chart.view.LineChartView;import com.db.chart.view.YController;import android.app.Activity;import android.graphics.Color;import android.os.Bundle;public class WilliamChartActivity extends Activity {//线性图表控件private static LineChartView mLineChart;private final static String[] mLabels = {"ANT", "GNU", "OWL", "APE", "COD","YAK", "RAM", "JAY"};@Overrideprotected void onCreate(Bundle savedInstanceState) {// TODO Auto-generated method stubsuper.onCreate(savedInstanceState);setContentView(R.layout.chart_layout);mLineChart = (LineChartView) findViewById(R.id.linechart);LineSet data;mLineChart.reset();int nSets = 2; //两条线int nPoints = 5; //每条线5个点for(int i = 0; i < nSets; i++){data = new LineSet();for(int j = 0; j < nPoints; j++)data.addPoint(new Point(mLabels[j], DataRetriever.randValue(0, 10)));data.setDots(DataRetriever.randBoolean()).setDotsColor(Color.parseColor(DataRetriever.getColor(DataRetriever.randNumber(0,2)))).setDotsRadius(DataRetriever.randDimen(4,7)).setLineThickness(DataRetriever.randDimen(3,8)).setLineColor(Color.parseColor(DataRetriever.getColor(i))).setDashed(DataRetriever.randBoolean()).setSmooth(DataRetriever.randBoolean());if(i == 2){//data.setFill(Color.parseColor("#3388c6c3"));int[] colors = {Color.parseColor("#3388c6c3"), Color.TRANSPARENT};data.setGradientFill(colors, null);}if(DataRetriever.randBoolean())data.setDotsStrokeThickness(DataRetriever.randDimen(1,4)).setDotsStrokeColor(Color.parseColor(DataRetriever.getColor(DataRetriever.randNumber(0,2))));mLineChart.addData(data);}mLineChart.setGrid(DataRetriever.randPaint()).setVerticalGrid(DataRetriever.randPaint()).setHorizontalGrid(DataRetriever.randPaint())//.setThresholdLine(2, randPaint()).setYLabels(YController.LabelPosition.NONE).setYAxis(false).setXLabels(DataRetriever.getXPosition()).setXAxis(DataRetriever.randBoolean()).setMaxAxisValue(10, 2).animate(DataRetriever.randAnimation(null, nPoints))//.show();}}
注意这个类中引用了拷贝过来的DataRetriever类。
运行该项目,效果如下:
其中的效果可以自己再另行操作。
0 0
- 安卓图表控件WilliamChart使用指南
- AnyChart图表控件使用指南(三)
- AnyChart图表控件使用指南(二)
- AnyChart图表控件使用指南(三)
- AnyChart图表控件使用指南(四)
- AnyChart图表控件使用指南(五)
- 微软图表控件MsChart使用指南
- 安卓学习笔记---图表控件 HelloCharts
- 安卓图表hellochart
- 安卓图表hellochart
- 安卓图表hellochart
- 安卓图表引擎AChartEngine
- 安卓图表引擎AChartEngine
- 安卓图表引擎AChartEngine
- 安卓图表引擎AChartEngine
- 安卓图表引擎AChartEngine
- 安卓图表框架AChartEngine
- 安卓自定义图表----柱状图
- Linux用户及权限基础
- 两个SVN仓库的同步----svnsync
- python 同时载入多个数据文件
- An internal error occurred during: "Launching New_configuration". Path for project must have only on
- 利用CMemDC画图的两种方法(解决绘图闪烁)
- 安卓图表控件WilliamChart使用指南
- 数据结构资料
- POJ 2935 BFS
- HashMap和Hashtable的区别
- 从源码编译nginx1.8.0 php5.6.8 mysql5.6.24
- android生命周期view事件分发的几张图片
- php 简单工厂模式
- 真正高效的SQLSERVER分页查询
- MyEclipse BASE64Encoder找不到jar包的解决方法