![
](https://img-blog.csdn.net/20170303173656836?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvcXFfMzA1MTkzNjU=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast)##线形图
* 构建运用建造者模式
* ###数据源-line-data-chart
使用思路:代码倒着写 如:
* @param chart 图表对象
* @param values 图标上点的集合
* 设置图表数据并配置x,y轴 参数
* @param isshowxy 是否显示 x,y轴
* @param color 线的颜色值
* @param issqure 描线是不是方形还是圆形 false 是方形 true 是圆形
实例:
rotected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_zz);
chart = (LineChartView) findViewById(R.id.chart);
chart.animate();
List values = new ArrayList();
values.add(new PointValue(78, 2));
values.add(new PointValue(10, 4));
values.add(new PointValue(2, 3));
values.add(new PointValue(3, 4));
setChatData(chart,values,true,Color.GREEN,false);
// setChatData(values,Color.RED,false,”x轴”,”y轴”,Color.YELLOW,Color.BLUE);
}
private void setChatData( List values, int red, boolean b, String xlabel, String ylable, int xtextclor, int ytextclor) {
showxy(values,red,xlabel,ylable,xtextclor,ytextclor);
}
private void showxy( List value,int red, String xlabel, String ylable, int xtextclor, int ytextclor) {
Line line = new Line(value).setColor(red).setCubic(false);
List lines = new ArrayList();
line.setHasLabelsOnlyForSelected(true);
lines.add(line);
data = new LineChartData();
data.setLines(lines);
Axis axis=new Axis();
axis.setName(xlabel);
axis.setTextColor(xtextclor);
data.setAxisXBottom(axis);
Axis axisy=new Axis();
axisy.setName(ylable);
axisy.setTextColor(ytextclor);
data.setAxisYLeft(axisy);
chart.setLineChartData(data);
}
/**
* @param chart 图表对象
* @param values 图标上点的集合
* 设置图表数据并配置x,y轴 参数
* 构建运用建造者模式
* 数据源-line-data-chart
* @param isshowxy 是否显示 x,y轴
* @param color 线的颜色值
* @param issqure 描线是不是方形还是圆形 false 是方形 true 是圆形
*/
LineChartData data;
private void setChatData(LineChartView chart,List<PointValue> values,Boolean isshowxy ,int color,Boolean issqure) {
//In most cased you can call data model methods in builder-pattern-like manner.
Line line = new Line(values).setColor(color).setCubic(issqure);
List<Line> lines = new ArrayList<Line>();
line.setHasLabelsOnlyForSelected(true);
lines.add(line);
data = new LineChartData();
if (isshowxy){
showxy(data);
}
data.setLines(lines);
chart.setLineChartData(data);
}
private void showxy(LineChartData data) {
Axis axis=new Axis();
axis.setLineColor(Color.RED);
axis.setName("x轴");
axis.setTextColor(Color.RED);
data.setAxisXBottom(axis);
Axis axisy=new Axis();
axisy.setLineColor(Color.YELLOW);
axisy.setName("y轴");
axisy.setTextColor(Color.BLUE);
data.setAxisYLeft(axisy);
}
饼状图
package com.example.administrator.phonelocationapp.chartspic;
import android.app.Activity;
import android.graphics.Color;
import android.graphics.RectF;
import android.os.Bundle;
import com.example.administrator.phonelocationapp.R;
import java.util.ArrayList;
import java.util.List;
import lecho.lib.hellocharts.model.Axis;
import lecho.lib.hellocharts.model.Line;
import lecho.lib.hellocharts.model.LineChartData;
import lecho.lib.hellocharts.model.PieChartData;
import lecho.lib.hellocharts.model.PointValue;
import lecho.lib.hellocharts.model.SliceValue;
import lecho.lib.hellocharts.view.LineChartView;
import lecho.lib.hellocharts.view.PieChartView;
/**
* Created by Administrator on 2017/3/3 0003.
*/
public class Piepic extends Activity {
PieChartView chart;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_pie);
chart = (PieChartView) findViewById(R.id.pc);
chart.animate();
List<SliceValue> values=new ArrayList<>();
values.add(new SliceValue(0.1f,Color.RED).setLabel("A"));
values.add(new SliceValue(0.2f,Color.YELLOW).setLabel("B"));
values.add(new SliceValue(0.3f,Color.BLUE).setLabel("C"));
values.add(new SliceValue(0.2f,Color.GREEN).setLabel("D"));
values.add(new SliceValue(0.2f,Color.WHITE).setLabel("E"));
PieChartData datas=new PieChartData(values);
datas.setHasLabelsOnlyForSelected(true);
datas.setCenterText2Color(Color.GREEN);
datas.setHasLabelsOutside(true);
datas.setCenterText2("第二圈");
chart.setViewportCalculationEnabled(true);//设置饼图自动适应大小
chart.setChartRotation(360,true);//设置饼图旋转角度,且是否为动画
chart.setChartRotationEnabled(true);//设置饼图是否可以手动旋转 默认可以的
chart.setCircleFillRatio(0.5f);//设置饼图其中的比例
chart.setCircleOval(new RectF());//设置饼图成椭圆形
//为饼图设置数据
chart.setPieChartData(datas);
}
}
气泡图
package com.example.administrator.phonelocationapp.chartspic;
import android.app.Activity;
import android.graphics.Color;
import android.os.Bundle;
import com.example.administrator.phonelocationapp.R;
import java.util.ArrayList;
import java.util.List;
import lecho.lib.hellocharts.model.Axis;
import lecho.lib.hellocharts.model.BubbleChartData;
import lecho.lib.hellocharts.model.BubbleValue;
import lecho.lib.hellocharts.view.BubbleChartView;
/**
* Created by Administrator on 2017/3/3 0003.
*/
public class Qipao extends Activity {
BubbleChartView bcv;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_qpao);
bcv= (BubbleChartView) findViewById(R.id.bubblechart);
List values=new ArrayList<>();
values.add(new BubbleValue(2.0f,3.0f,4.0f, Color.BLUE));
values.add(new BubbleValue(2.6f,3.7f,4.08f, Color.YELLOW));
values.add(new BubbleValue(2.090f,3.0f,4.07f, Color.GREEN));
values.add(new BubbleValue(2.06f,3.066f,4.09f, Color.RED));
values.add(new BubbleValue(2.07f,3.089f,4.067f, Color.DKGRAY));
BubbleChartData datas=new BubbleChartData(values);
datas.setHasLabelsOnlyForSelected(true);
Axis ax=new Axis();
ax.setName(“x轴”);
ax.setTextColor(Color.BLUE);
datas.setAxisXBottom(ax);
Axis ay=new Axis();
ay.setTextColor(Color.GREEN);
ay.setName(“y轴”);
datas.setAxisYLeft(ay);
bcv.setBubbleChartData(datas);
}
}
折线图
setContentView(R.layout.activity_zz);
chart = (LineChartView) findViewById(R.id.chart);
chart.animate();
List<PointValue> values = new ArrayList<PointValue>();
values.add(new PointValue(78, 2));
values.add(new PointValue(10, 4));
values.add(new PointValue(2, 3));
values.add(new PointValue(3, 4));
setChatData(chart,values,true,Color.GREEN,false);
// setChatData(values,Color.RED,false,"x轴","y轴",Color.YELLOW,Color.BLUE);
}
private void setChatData( List<PointValue> values, int red, boolean b, String xlabel, String ylable, int xtextclor, int ytextclor) {
showxy(values,red,xlabel,ylable,xtextclor,ytextclor);
}
private void showxy( List<PointValue> value,int red, String xlabel, String ylable, int xtextclor, int ytextclor) {
Line line = new Line(value).setColor(red).setCubic(false);
List<Line> lines = new ArrayList<Line>();
line.setHasLabelsOnlyForSelected(true);
lines.add(line);
data = new LineChartData();
data.setLines(lines);
Axis axis=new Axis();
axis.setName(xlabel);
axis.setTextColor(xtextclor);
data.setAxisXBottom(axis);
Axis axisy=new Axis();
axisy.setName(ylable);
axisy.setTextColor(ytextclor);
data.setAxisYLeft(axisy);
chart.setLineChartData(data);
}
/**
* @param chart 图表对象
* @param values 图标上点的集合
* 设置图表数据并配置x,y轴 参数
* 构建运用建造者模式
* 数据源-line-data-chart
* @param isshowxy 是否显示 x,y轴
* @param color 线的颜色值
* @param issqure 描线是不是方形还是圆形 false 是方形 true 是圆形
*/
LineChartData data;
private void setChatData(LineChartView chart,List<PointValue> values,Boolean isshowxy ,int color,Boolean issqure) {
//In most cased you can call data model methods in builder-pattern-like manner.
Line line = new Line(values).setColor(color).setCubic(issqure);
List<Line> lines = new ArrayList<Line>();
line.setHasLabelsOnlyForSelected(true);
lines.add(line);
data = new LineChartData();
if (isshowxy){
showxy(data);
}
data.setLines(lines);
chart.setLineChartData(data);
}
private void showxy(LineChartData data) {
Axis axis=new Axis();
axis.setLineColor(Color.RED);
axis.setName("x轴");
axis.setTextColor(Color.RED);
data.setAxisXBottom(axis);
Axis axisy=new Axis();
axisy.setLineColor(Color.YELLOW);
axisy.setName("y轴");
axisy.setTextColor(Color.BLUE);
data.setAxisYLeft(axisy);
}
柱状图
ColumnChartView cv;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_zzpic);
cv= (ColumnChartView) findViewById(R.id.cc);
List colums=new ArrayList<>();
List values=new ArrayList<>();
values.add(new SubcolumnValue(2.3f, Color.GREEN));
values.add(new SubcolumnValue(4.3f, Color.RED));
values.add(new SubcolumnValue(2.5f, Color.YELLOW));
values.add(new SubcolumnValue(2.3f, Color.BLUE));
colums.add(new Column(values));
ColumnChartData mdata=new ColumnChartData(colums);
ArrayList axisValuesX = new ArrayList();//定义X轴刻度值的数据集合
axisValuesX.add(new AxisValue(1.0f));
axisValuesX.add(new AxisValue(5.0f));
axisValuesX.add(new AxisValue(6.0f));
axisValuesX.add(new AxisValue(7.0f));
axisValuesX.add(new AxisValue(100.0f));
ArrayList axisValuesY = new ArrayList();//定义Y轴刻度值的数据集合
axisValuesY.add(new AxisValue(1.0f));
axisValuesY.add(new AxisValue(5.0f));
axisValuesY.add(new AxisValue(6.0f));
axisValuesY.add(new AxisValue(7.0f));
axisValuesY.add(new AxisValue(100.0f));
Axis ax=new Axis();
ax.setName(“x轴”);
ax.setTextColor(Color.BLUE);
ax.setLineColor(Color.WHITE);
Axis ay=new Axis();
ay.setName("y轴");
ay.setTextColor(Color.RED);
mdata.setAxisYLeft(ay);
mdata.setAxisXBottom(ax);
cv.setColumnChartData(mdata);
}