Android 第三方框架之Charts
概述:此框架专门用来做k线等金融行业的交易线,包括k线和阴阳烛等曲线,操作简便,功能强大
1、GirdChart(网格图表,没有线)
public class Demotextactivity extends Activity {
private GridChart gridchart;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main1);
this.gridchart = (GridChart) findViewById(R.id.gridchart);
List<String> ytitle = new ArrayList<String>();//y轴坐标(基本点 坐标)
ytitle.add("241");
ytitle.add("242");
ytitle.add("243");
ytitle.add("244");
ytitle.add("245");
List<String> xtitle = new ArrayList<String>();//x轴坐标(时间)
xtitle.add("9:00");
xtitle.add("10:00");
xtitle.add("11:00");
xtitle.add("13:00");
xtitle.add("14:00");
xtitle.add("15:00");
gridchart.setAxisXColor(Color.GREEN);//x轴颜色
gridchart.setAxisYColor(Color.RED);//y轴颜色似乎不好用
gridchart.setAxisWidth(1);//设置xy轴宽度
gridchart.setLatitudeNum(5);//5条纬度线
gridchart.setLongitudeNum(6);//6条经度线
gridchart.setDataQuadrantPaddingTop(5);//数据距离象限顶部的内边距
gridchart.setDataQuadrantPaddingBottom(5);//数据距离象限底部内边距
gridchart.setDataQuadrantPaddingRight(5);//数据距离象限右边内边距
gridchart.setDataQuadrantPaddingLeft(5);//数据距离象限左部内边距
gridchart.setAxisYTitleQuadrantWidth(50);//添加y轴空白,做参数描述用
gridchart.setAxisXTitleQuadrantHeight(20);//添加x轴空白,做参数描述用
gridchart.setAxisXPosition(GridChart.AXIS_X_POSITION_BOTTOM);//可能是曲线起始坐标点
gridchart.setAxisYPosition(GridChart.AXIS_Y_POSITION_RIGHT);
gridchart.setLatitudeTitles(ytitle);//添加y轴标签数组
gridchart.setLongitudeTitles(xtitle);//添加x轴数据
gridchart.setLongitudeFontSize(14);//数据字体大小
gridchart.setLatitudeFontSize(14);//数据字体大小
gridchart.setLongitudeFontColor(Color.GRAY);//经度数据颜色
gridchart.setLatitudeFontColor(Color.GRAY);//纬度数据颜色
gridchart.setLatitudeColor(Color.RED);//纬度线颜色
gridchart.setLongitudeColor(Color.GREEN);//经度线颜色
gridchart.setDisplayLongitudeTitle(true);//是否显示经度数据
gridchart.setDisplayLatitudeTitle(true);//是否显示纬度数据
gridchart.setDisplayLatitude(true);//是否显示纬度线
gridchart.setDisplayLongitude(true);//是否显示经度线
gridchart.setCrossLinesColor(Color.BLUE);//设置实时显示指示线颜色
gridchart.setCrossLinesFontColor(Color.GREEN);//实时显示线指向的数据颜色
gridchart.setBorderWidth(1);//设置边框宽度
gridchart.setBorderColor(Color.YELLOW);//外边框
}
}
<cn.limc.androidcharts.view.GridChart
android:id="@+id/gridchart"
android:layout_width="360dp"
android:layout_height="240dp" />
2、LineChart(网格图表里面添加线)
public class Demotextactivity extends Activity {
private LineChart linechart;
List<IStickEntity> ohlc;
List<LineEntity<DateValueEntity>> lines;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main1);
this.linechart = (LineChart) findViewById(R.id.linechart);
initOHLC();//初始化数据,O开盘汇率,H最高汇率,L最低汇率,C收盘汇率
initlinchart();//初始化表格样式
initline();//初始化均线
linechart.setLinesData(lines); // 将均线添加到表里
}
private void initline() {
lines = new ArrayList<LineEntity<DateValueEntity>>();//创建集合存放总线数
// 计算5日均线
LineEntity<DateValueEntity> MA5 = new LineEntity<DateValueEntity>();//创建线条
MA5.setTitle("MA5");//设置标题,似乎没什么用
MA5.setLineColor(Color.WHITE);//设置线条颜色
MA5.setLineData(initMA(5));//解析算法,5日,10日,25日均线
lines.add(MA5);
// 计算10日均线
LineEntity<DateValueEntity> MA10 = new LineEntity<DateValueEntity>();
MA10.setTitle("MA10");
MA10.setLineColor(Color.RED);
MA10.setLineData(initMA(10));
lines.add(MA10);
// 计算25日均线
LineEntity<DateValueEntity> MA25 = new LineEntity<DateValueEntity>();
MA25.setTitle("MA25");
MA25.setLineColor(Color.GREEN);
MA25.setLineData(initMA(25));
lines.add(MA25);
}
private void initlinchart() {
linechart.setMaxValue(280);//不清楚有什么用
linechart.setMinValue(240);
linechart.setMaxPointNum(36);//设置点密集程度,不确定,值越小曲线越平滑
linechart.setAxisXColor(Color.LTGRAY);
linechart.setAxisYColor(Color.LTGRAY);
linechart.setBorderColor(Color.LTGRAY);
linechart.setLongitudeFontSize(14);
linechart.setLongitudeFontColor(Color.WHITE);
linechart.setLatitudeColor(Color.GRAY);
linechart.setLatitudeFontColor(Color.WHITE);
linechart.setLongitudeColor(Color.GRAY);
linechart.setDisplayLongitudeTitle(true);
linechart.setDisplayLatitudeTitle(true);
linechart.setDisplayLatitude(true);
linechart.setDisplayLongitude(true);
linechart.setLatitudeNum(5);
linechart.setLongitudeNum(6);
linechart.setDataQuadrantPaddingTop(5);
linechart.setDataQuadrantPaddingBottom(5);
linechart.setDataQuadrantPaddingLeft(5);
linechart.setDataQuadrantPaddingRight(5);
linechart.setAxisYTitleQuadrantWidth(50);
linechart.setAxisXTitleQuadrantHeight(20);
linechart.setAxisXPosition(GridChart.AXIS_X_POSITION_BOTTOM);
linechart.setAxisYPosition(GridChart.AXIS_Y_POSITION_RIGHT);
}
private List<DateValueEntity> initMA(int days) {
if (days < 2) {
return null;
}
List<DateValueEntity> MA5Values = new ArrayList<DateValueEntity>();
float sum = 0;
float avg = 0;
for (int i = 0; i < this.ohlc.size(); i++) {
float close = (float) ((OHLCEntity) ohlc.get(i)).getClose();
if (i < days) {
sum = sum + close;
avg = sum / (i + 1f);
} else {
sum = sum + close
- (float) ((OHLCEntity) ohlc.get(i - days)).getClose();
avg = sum / days;
}
MA5Values.add(new DateValueEntity(avg, ohlc.get(i).getDate()));
}
return MA5Values;
}
private void initOHLC() {
List<IStickEntity> ohlc = new ArrayList<IStickEntity>();
this.ohlc = new ArrayList<IStickEntity>();
ohlc.add(new OHLCEntity(986, 1015, 977, 1003, 20130424));
ohlc.add(new OHLCEntity(1000, 1007, 982, 991, 20130425));
ohlc.add(new OHLCEntity(996, 1001, 985, 988, 20130426));
ohlc.add(new OHLCEntity(977, 986, 966, 982, 20130502));
ohlc.add(new OHLCEntity(987, 1017, 983, 1001, 20130503));
ohlc.add(new OHLCEntity(1003, 1021, 997, 1013, 20130506));
ohlc.add(new OHLCEntity(1009, 1010, 998, 1006, 20130507));
ohlc.add(new OHLCEntity(1012, 1020, 1001, 1005, 20130508));
ohlc.add(new OHLCEntity(1006, 1008, 989, 997, 20130509));
ohlc.add(new OHLCEntity(993, 1006, 989, 1003, 20130510));
ohlc.add(new OHLCEntity(1002, 1011, 993, 1002, 20130513));
ohlc.add(new OHLCEntity(1003, 1005, 993, 997, 20130514));
ohlc.add(new OHLCEntity(998, 1002, 993, 999, 20130515));
ohlc.add(new OHLCEntity(999, 1016, 984, 1015, 20130516));
ohlc.add(new OHLCEntity(1015, 1028, 1005, 1024, 20130517));
ohlc.add(new OHLCEntity(1026, 1054, 1020, 1041, 20130520));
ohlc.add(new OHLCEntity(1038, 1042, 1024, 1034, 20130521));
ohlc.add(new OHLCEntity(1033, 1038, 1028, 1036, 20130522));
ohlc.add(new OHLCEntity(1029, 1033, 1015, 1015, 20130523));
ohlc.add(new OHLCEntity(1020, 1028, 1010, 1020, 20130524));
ohlc.add(new OHLCEntity(1021, 1033, 1018, 1029, 20130527));
ohlc.add(new OHLCEntity(1030, 1056, 1025, 1055, 20130528));
ohlc.add(new OHLCEntity(1058, 1062, 1051, 1052, 20130529));
ohlc.add(new OHLCEntity(1048, 1062, 1047, 1054, 20130530));
ohlc.add(new OHLCEntity(1056, 1062, 1046, 1047, 20130531));
ohlc.add(new OHLCEntity(997, 1001, 981, 984, 20130603));
ohlc.add(new OHLCEntity(989, 989, 970, 974, 20130604));
ohlc.add(new OHLCEntity(974, 977, 960, 965, 20130605));
ohlc.add(new OHLCEntity(961, 967, 942, 945, 20130606));
ohlc.add(new OHLCEntity(951, 957, 932, 935, 20130607));
ohlc.add(new OHLCEntity(925, 925, 891, 902, 20130613));
ohlc.add(new OHLCEntity(907, 907, 898, 902, 20130614));
ohlc.add(new OHLCEntity(905, 910, 896, 901, 20130617));
ohlc.add(new OHLCEntity(905, 912, 901, 907, 20130618));
ohlc.add(new OHLCEntity(905, 905, 882, 889, 20130619));
ohlc.add(new OHLCEntity(886, 886, 840, 842, 20130620));
ohlc.add(new OHLCEntity(831, 847, 822, 828, 20130621));
ohlc.add(new OHLCEntity(829, 829, 750, 752, 20130624));
ohlc.add(new OHLCEntity(745, 784, 718, 780, 20130625));
ohlc.add(new OHLCEntity(790, 795, 763, 777, 20130626));
ohlc.add(new OHLCEntity(785, 792, 770, 788, 20130627));
ohlc.add(new OHLCEntity(782, 830, 776, 828, 20130628));
ohlc.add(new OHLCEntity(822, 827, 807, 817, 20130701));
ohlc.add(new OHLCEntity(818, 822, 795, 815, 20130702));
ohlc.add(new OHLCEntity(810, 811, 797, 804, 20130703));
ohlc.add(new OHLCEntity(806, 828, 802, 812, 20130704));
ohlc.add(new OHLCEntity(811, 822, 808, 811, 20130705));
ohlc.add(new OHLCEntity(800, 805, 790, 791, 20130708));
ohlc.add(new OHLCEntity(792, 796, 788, 792, 20130709));
ohlc.add(new OHLCEntity(795, 813, 790, 811, 20130710));
ohlc.add(new OHLCEntity(817, 892, 817, 886, 20130711));
ohlc.add(new OHLCEntity(876, 885, 843, 849, 20130712));
ohlc.add(new OHLCEntity(855, 871, 841, 856, 20130715));
ohlc.add(new OHLCEntity(852, 855, 841, 854, 20130716));
ohlc.add(new OHLCEntity(852, 855, 838, 845, 20130717));
ohlc.add(new OHLCEntity(841, 845, 816, 820, 20130718));
ohlc.add(new OHLCEntity(822, 824, 802, 803, 20130719));
ohlc.add(new OHLCEntity(790, 799, 782, 795, 20130722));
ohlc.add(new OHLCEntity(799, 823, 794, 814, 20130723));
ohlc.add(new OHLCEntity(804, 809, 790, 800, 20130724));
ohlc.add(new OHLCEntity(802, 811, 796, 802, 20130725));
ohlc.add(new OHLCEntity(798, 801, 794, 797, 20130726));
ohlc.add(new OHLCEntity(790, 790, 771, 774, 20130729));
ohlc.add(new OHLCEntity(778, 796, 774, 784, 20130730));
ohlc.add(new OHLCEntity(791, 802, 782, 786, 20130731));
ohlc.add(new OHLCEntity(792, 802, 787, 799, 20130801));
ohlc.add(new OHLCEntity(806, 812, 797, 798, 20130802));
ohlc.add(new OHLCEntity(798, 807, 795, 806, 20130805));
ohlc.add(new OHLCEntity(803, 808, 798, 803, 20130806));
ohlc.add(new OHLCEntity(803, 814, 800, 801, 20130807));
ohlc.add(new OHLCEntity(801, 807, 795, 799, 20130808));
ohlc.add(new OHLCEntity(805, 808, 796, 801, 20130809));
ohlc.add(new OHLCEntity(804, 832, 801, 831, 20130812));
ohlc.add(new OHLCEntity(830, 843, 827, 842, 20130813));
ohlc.add(new OHLCEntity(844, 853, 830, 831, 20130814));
ohlc.add(new OHLCEntity(831, 837, 820, 822, 20130815));
ohlc.add(new OHLCEntity(817, 904, 815, 831, 20130816));
ohlc.add(new OHLCEntity(824, 850, 823, 845, 20130819));
ohlc.add(new OHLCEntity(842, 878, 839, 851, 20130820));
ohlc.add(new OHLCEntity(853, 858, 837, 845, 20130821));
ohlc.add(new OHLCEntity(841, 862, 840, 844, 20130822));
ohlc.add(new OHLCEntity(854, 863, 825, 842, 20130823));
ohlc.add(new OHLCEntity(845, 878, 840, 874, 20130826));
ohlc.add(new OHLCEntity(875, 905, 870, 895, 20130827));
ohlc.add(new OHLCEntity(888, 915, 879, 900, 20130828));
ohlc.add(new OHLCEntity(911, 921, 886, 892, 20130829));
ohlc.add(new OHLCEntity(886, 905, 876, 899, 20130830));
ohlc.add(new OHLCEntity(911, 929, 895, 897, 20130902));
ohlc.add(new OHLCEntity(896, 912, 889, 909, 20130903));
ohlc.add(new OHLCEntity(904, 924, 903, 914, 20130904));
ohlc.add(new OHLCEntity(919, 919, 906, 913, 20130905));
ohlc.add(new OHLCEntity(915, 987, 912, 957, 20130906));
ohlc.add(new OHLCEntity(1028, 1053, 1018, 1053, 20130909));
ohlc.add(new OHLCEntity(1100, 1149, 1077, 1140, 20130910));
ohlc.add(new OHLCEntity(1121, 1147, 1120, 1127, 20130911));
ohlc.add(new OHLCEntity(1130, 1240, 1116, 1225, 20130912));
ohlc.add(new OHLCEntity(1208, 1227, 1173, 1191, 20130913));
ohlc.add(new OHLCEntity(1200, 1202, 1123, 1149, 20130916));
ohlc.add(new OHLCEntity(1141, 1148, 1077, 1083, 20130917));
ohlc.add(new OHLCEntity(1095, 1119, 1083, 1100, 20130918));
ohlc.add(new OHLCEntity(1105, 1120, 1080, 1118, 20130923));
ohlc.add(new OHLCEntity(1119, 1120, 1057, 1081, 20130924));
ohlc.add(new OHLCEntity(1074, 1118, 1069, 1078, 20130925));
ohlc.add(new OHLCEntity(1075, 1076, 1007, 1017, 20130926));
ohlc.add(new OHLCEntity(1011, 1033, 1005, 1024, 20130927));
ohlc.add(new OHLCEntity(1034, 1037, 1002, 1009, 20130930));
ohlc.add(new OHLCEntity(1003, 1033, 988, 1023, 20131008));
ohlc.add(new OHLCEntity(1010, 1046, 1007, 1027, 20131009));
ohlc.add(new OHLCEntity(1030, 1035, 993, 998, 20131010));
ohlc.add(new OHLCEntity(1010, 1065, 1000, 1055, 20131011));
ohlc.add(new OHLCEntity(1045, 1050, 1025, 1029, 20131014));
ohlc.add(new OHLCEntity(1030, 1035, 1002, 1011, 20131015));
ohlc.add(new OHLCEntity(1009, 1009, 982, 991, 20131016));
ohlc.add(new OHLCEntity(1001, 1007, 981, 982, 20131017));
ohlc.add(new OHLCEntity(982, 1006, 980, 988, 20131018));
ohlc.add(new OHLCEntity(995, 1016, 980, 1012, 20131021));
ohlc.add(new OHLCEntity(1011, 1011, 986, 993, 20131022));
ohlc.add(new OHLCEntity(995, 1035, 991, 1002, 20131023));
ohlc.add(new OHLCEntity(996, 1016, 982, 998, 20131024));
ohlc.add(new OHLCEntity(1001, 1026, 999, 1007, 20131025));
ohlc.add(new OHLCEntity(1008, 1022, 992, 1015, 20131028));
ohlc.add(new OHLCEntity(1022, 1069, 1018, 1048, 20131029));
ohlc.add(new OHLCEntity(1048, 1062, 1031, 1059, 20131030));
ohlc.add(new OHLCEntity(1058, 1060, 1031, 1033, 20131031));
ohlc.add(new OHLCEntity(1032, 1053, 1023, 1042, 20131101));
ohlc.add(new OHLCEntity(1048, 1054, 1026, 1030, 20131104));
this.ohlc.addAll(ohlc);
}
}
3、SlipLineChart(细线图表和上表类似)
private void initSlipLineChart() {
this.sliplinechart = (SlipLineChart) findViewById(R.id.sliplinechart);
List<LineEntity<DateValueEntity>> lines = new ArrayList<LineEntity<DateValueEntity>>();
// 计算5日均线
LineEntity<DateValueEntity> MA5 = new LineEntity<DateValueEntity>();
MA5.setTitle("HIGH");//数据为每日最高值的集合
MA5.setLineColor(Color.WHITE);
MA5.setLineData(dv1);
lines.add(MA5);
// 计算10日均线
LineEntity<DateValueEntity> MA10 = new LineEntity<DateValueEntity>();
MA10.setTitle("LOW");//数据为每日最低值的集合
MA10.setLineColor(Color.RED);
MA10.setLineData(dv2);
lines.add(MA10);
sliplinechart.setAxisXColor(Color.LTGRAY);
sliplinechart.setAxisYColor(Color.LTGRAY);
sliplinechart.setBorderColor(Color.LTGRAY);
sliplinechart.setLongitudeFontSize(14);
sliplinechart.setLongitudeFontColor(Color.WHITE);
sliplinechart.setLatitudeColor(Color.GRAY);
sliplinechart.setLatitudeFontColor(Color.WHITE);
sliplinechart.setLongitudeColor(Color.GRAY);
sliplinechart.setMaxValue(1300);
sliplinechart.setMinValue(700);
sliplinechart.setDisplayFrom(10);
sliplinechart.setDisplayNumber(30);
sliplinechart.setMinDisplayNumber(5);
sliplinechart.setZoomBaseLine(IZoomable.ZOOM_BASE_LINE_CENTER);//设置缩放基准线
sliplinechart.setDisplayLongitudeTitle(true);
sliplinechart.setDisplayLatitudeTitle(true);
sliplinechart.setDisplayLatitude(true);
sliplinechart.setDisplayLongitude(true);
sliplinechart.setDataQuadrantPaddingTop(5);
sliplinechart.setDataQuadrantPaddingBottom(5);
sliplinechart.setDataQuadrantPaddingLeft(5);
sliplinechart.setDataQuadrantPaddingRight(5);
sliplinechart.setAxisYTitleQuadrantWidth(50);
sliplinechart.setAxisXTitleQuadrantHeight(20);
sliplinechart.setAxisXPosition(GridChart.AXIS_X_POSITION_BOTTOM);
sliplinechart.setAxisYPosition(GridChart.AXIS_Y_POSITION_RIGHT);
sliplinechart.setLinesData(lines);
}
<cn.limc.androidcharts.view.SlipLineChart
android:id="@+id/sliplinechart"
android:layout_width="fill_parent"
android:layout_height="240dip" />
dv.add(new DateValueEntity(947.3056f, 20130424));//数据结构
4、SlipAreaChart(覆盖区域图表)
this.slipareachart = (SlipAreaChart) findViewById(R.id.slipareachart);//其他设置同slipchart
<cn.limc.androidcharts.view.SlipAreaChart
android:id="@+id/slipareachart"
android:layout_width="fill_parent"
android:layout_height="240dip" />5、SlipBandChart(交叉区域图表)
this.slipbandchart = (SlipBandAreaChart) findViewById(R.id.slipbandchart);<cn.limc.androidcharts.view.SlipBandAreaChart
android:id="@+id/slipbandchart"
android:layout_width="fill_parent"
android:layout_height="240dip" />
5、StickChart(柱状图)
private void initStickChart() {
this.stickchart = (StickChart) findViewById(R.id.stickchart);//柱状图表
//此设置同Gridchart
stickchart.setAxisXColor(Color.LTGRAY);
stickchart.setAxisYColor(Color.LTGRAY);
stickchart.setLatitudeColor(Color.GRAY);
stickchart.setLongitudeColor(Color.GRAY);
stickchart.setBorderColor(Color.LTGRAY);
stickchart.setLongitudeFontColor(Color.WHITE);
stickchart.setLatitudeFontColor(Color.WHITE);
stickchart.setDataQuadrantPaddingTop(6);
stickchart.setDataQuadrantPaddingBottom(1);
stickchart.setDataQuadrantPaddingLeft(1);
stickchart.setDataQuadrantPaddingRight(1);
stickchart.setAxisYTitleQuadrantWidth(50);
stickchart.setAxisXTitleQuadrantHeight(20);
stickchart.setAxisXPosition(GridChart.AXIS_X_POSITION_BOTTOM);
stickchart.setAxisYPosition(GridChart.AXIS_Y_POSITION_RIGHT);
// 最大显示足数
stickchart.setMaxSticksNum(52);
// 最大纬线数
stickchart.setLatitudeNum(2);
// 最大经线数
stickchart.setLongitudeNum(3);
// 最大价格(传入数据最大值,超出此值不显示,不是很明白)
stickchart.setMaxValue(10000);
// 最小价格
stickchart.setMinValue(100);
stickchart.setDisplayLongitudeTitle(true);
stickchart.setDisplayLatitudeTitle(true);
stickchart.setDisplayLatitude(true);
stickchart.setDisplayLongitude(true);
stickchart.setBackgroundColor(Color.BLACK);
stickchart.setDataMultiple(100);//不明白
stickchart.setAxisYDecimalFormat("#,##0.00");//设置y轴数据格式
stickchart.setAxisXDateTargetFormat("yyyy/MM/dd");//设置x固定时间格式
stickchart.setAxisXDateSourceFormat("yyyyMMdd");//设置x当前时间格式
// 为chart1增加均线
stickchart.setStickData(new ListChartData<IStickEntity>(vol));
}<cn.limc.androidcharts.view.StickChart
android:id="@+id/stickchart"
android:layout_width="fill_parent"
android:layout_height="240dip" />List<IStickEntity> stick = new ArrayList<IStickEntity>();//数据结构6、SlipStickChart(不明白)
stick.add(new StickEntity(406000, 0, 20110825));
slipstickchart.setLongitudeNum(3);7、
// 最大价格,与上图比,数据变大,上图是10000
slipstickchart.setMaxValue(600000);IChartData<IStickEntity> vol = new ListChartData<IStickEntity>(this.vol);//其他无区别
// 添加此句话,将数据固定
slipstickchart.setStickData(vol);<cn.limc.androidcharts.view.SlipStickChart
android:id="@+id/slipstickchart"
android:layout_width="fill_parent"
android:layout_height="240dip" />ColoredSlipStickChart(带颜色柱状图)
this.coloredslipstickchart = (ColoredSlipStickChart) findViewById(R.id.coloredslipstickchart);coloredslipstickchart.setBackgroundColor(Color.BLACK);//柱条颜色没找到<cn.limc.androidcharts.view.ColoredSlipStickChart
android:id="@+id/coloredslipstickchart"
android:layout_width="fill_parent"
android:layout_height="240dip" />8、MAStickChart(带日均线的柱状图)
this.mastickchart = (MAStickChart) findViewById(R.id.mastickchart);
// 以下计算VOL
List<LineEntity<DateValueEntity>> vlines = new ArrayList<LineEntity<DateValueEntity>>();
// 计算5日均线
LineEntity<DateValueEntity> VMA5 = new LineEntity<DateValueEntity>();
VMA5.setTitle("MA5");
VMA5.setLineColor(Color.WHITE);
VMA5.setLineData(initVMA(5));
vlines.add(VMA5);
// 计算10日均线
LineEntity<DateValueEntity> VMA10 = new LineEntity<DateValueEntity>();
VMA10.setTitle("MA10");
VMA10.setLineColor(Color.RED);
VMA10.setLineData(initVMA(10));
vlines.add(VMA10);
// 计算25日均线
LineEntity<DateValueEntity> VMA25 = new LineEntity<DateValueEntity>();
VMA25.setTitle("MA25");
VMA25.setLineColor(Color.GREEN);
VMA25.setLineData(initVMA(25));
vlines.add(VMA25);
// 为chart1增加均线
mastickchart.setLinesData(vlines);
// 为chart1增加均线
mastickchart.setStickData(new ListChartData<IStickEntity>(vol));
<cn.limc.androidcharts.view.MAStickChart
android:id="@+id/mastickchart"
android:layout_width="fill_parent"
android:layout_height="240dip" />
9、MASlipStickChart(详情曲线柱状图)
this.maslipstickchart = (MASlipStickChart) findViewById(R.id.maslipstickchart);
// 只修改了最大价格
maslipstickchart.setMaxValue(600000);
<cn.limc.androidcharts.view.MASlipStickChart
android:id="@+id/maslipstickchart"
android:layout_width="fill_parent"
android:layout_height="240dip" />
10、MusicStickChart
private void initMinusStickChart() {
this.minusstickchart = (MinusStickChart) findViewById(R.id.minusstickchart);
List<IStickEntity> data = new ArrayList<IStickEntity>();
data.add(new StickEntity(50000, 0, 20110603)); data.add(new StickEntity(0, -12000, 20111003));
minusstickchart.setStickData(new ListChartData<IStickEntity>(data));
minusstickchart.setMaxSticksNum(data.size());
minusstickchart.setMaxValue(50000);
minusstickchart.setMinValue(-50000);
}
<cn.limc.androidcharts.view.MinusStickChart
android:id="@+id/minusstickchart"
android:layout_width="fill_parent"
android:layout_height="240dip" />
10、MusicStickChart
this.slipminusstickchart = (SlipMinusStickChart) findViewById(R.id.slipminusstickchart);
List<IStickEntity> data = new ArrayList<IStickEntity>();
data.add(new StickEntity(50000, 0, 20110603));
data.add(new StickEntity(0, -41000, 20111203));
11、SlipMinusStickChart
this.slipminusstickchart = (SlipMinusStickChart) findViewById(R.id.slipminusstickchart);
List<IStickEntity> data = new ArrayList<IStickEntity>();
data.add(new StickEntity(50000, 0, 20110603));
data.add(new StickEntity(0, -12000, 20111003));
data.add(new StickEntity(0, -28000, 20111103));
slipminusstickchart.setDisplayFrom(0);//从第几条开始显示
slipminusstickchart.setDisplayCrossXOnTouch(false);//设置没有交叉线
slipminusstickchart.setStickSpacing(10);//设置柱间距
<cn.limc.androidcharts.view.SlipMinusStickChart
android:id="@+id/slipminusstickchart"
android:layout_width="fill_parent"
android:layout_height="240dip" />
12、CandleStickChart(阴阳烛)
this.candlestickchart = (CandleStickChart) findViewById(R.id.candlestickchart);// 最大显示足数
candlestickchart.setMaxSticksNum(52);
// 最大纬线数
candlestickchart.setLatitudeNum(5);
// 最大经线数
candlestickchart.setLongitudeNum(3);
// 最大价格
candlestickchart.setMaxValue(1200);
// 最小价格
candlestickchart.setMinValue(200);<cn.limc.androidcharts.view.CandleStickChart13、
android:id="@+id/candlestickchart"
android:layout_width="fill_parent"
android:layout_height="240dip" />MASlipCandleStickChart(带日均线)
this.maslipcandlestickchart = (MASlipCandleStickChart) findViewById(R.id.maslipcandlestickchart);
List<LineEntity<DateValueEntity>> lines = new ArrayList<LineEntity<DateValueEntity>>();
// 计算5日均线
LineEntity<DateValueEntity> MA5 = new LineEntity<DateValueEntity>();
MA5.setTitle("MA5");
MA5.setLineColor(Color.WHITE);
MA5.setLineData(initMA(5));
lines.add(MA5);
14、
this.maslipcandlestickchart = (MASlipCandleStickChart) findViewById(R.id.maslipcandlestickchart);
List<LineEntity<DateValueEntity>> lines = new ArrayList<LineEntity<DateValueEntity>>();maslipcandlestickchart.setOnDisplayCursorListener(new IDisplayCursorListener() {
public void onCursorChanged(IDataCursor dataCursor, int displayFrom,
int displayNumber) {
bollmaslipcandlestickchart.setDisplayFrom(displayFrom);
bollmaslipcandlestickchart.setDisplayNumber(displayNumber);
bollmaslipcandlestickchart.postInvalidate();
}
});
maslipcandlestickchart.setOnTouchGestureListener(new OnTouchGestureListener(){
/* (non-Javadoc)
*
* @param touchable
* @param event
* @see cn.limc.androidcharts.event.OnTouchGestureListener#onTouchDown(cn.limc.androidcharts.event.ITouchable, android.view.MotionEvent)
*/
@Override
public void onTouchDown(ITouchable touchable, MotionEvent event) {
super.onTouchDown(touchable, event);
bollmaslipcandlestickchart.touchDown(new PointF(event.getX(),event.getY()));
}
/* (non-Javadoc)
*
* @param touchable
* @param event
* @see cn.limc.androidcharts.event.OnTouchGestureListener#onTouchMoved(cn.limc.androidcharts.event.ITouchable, android.view.MotionEvent)
*/
@Override
public void onTouchMoved(ITouchable touchable, MotionEvent event) {
super.onTouchMoved(touchable, event);
bollmaslipcandlestickchart.touchMoved(new PointF(event.getX(),event.getY()));
}
/* (non-Javadoc)
*
* @param touchable
* @param event
* @see cn.limc.androidcharts.event.OnTouchGestureListener#onTouchUp(cn.limc.androidcharts.event.ITouchable, android.view.MotionEvent)
*/
@Override
public void onTouchUp(ITouchable touchable, MotionEvent event) {
super.onTouchUp(touchable, event);
bollmaslipcandlestickchart.touchUp(new PointF(event.getX(),event.getY()));
}
});<cn.limc.androidcharts.view.MASlipCandleStickChart15、
android:id="@+id/maslipcandlestickchart"
android:layout_width="fill_parent"
android:layout_height="240dip" />PieChart(饼状图)<cn.limc.androidcharts.view.PieChart
android:id="@+id/piechart"
android:layout_width="fill_parent"
android:layout_height="240dip" />
private void initPieChart() {16、
this.piechart = (PieChart) findViewById(R.id.piechart);
List<TitleValueColorEntity> data3 = new ArrayList<TitleValueColorEntity>();
data3.add(new TitleValueColorEntity(getResources().getString(
R.string.piechart_title1), 2, getResources().getColor(
R.drawable.red)));
data3.add(new TitleValueColorEntity(getResources().getString(R.string.piechart_title2), 3, getResources().getColor(
R.drawable.orange)));
data3.add(new TitleValueColorEntity(getResources().getString(
R.string.piechart_title3), 6, getResources().getColor(
R.drawable.yellow)));
data3.add(new TitleValueColorEntity(getResources().getString(
R.string.piechart_title4), 2, getResources().getColor(
R.drawable.lightgreen)));
data3.add(new TitleValueColorEntity(getResources().getString(
R.string.piechart_title5), 2, getResources().getColor(
R.drawable.green)));
piechart.setData(data3);
}SpiderWebChart(蛛网图)
private void initSpiderWebChart() {
this.spiderwebchart = (SpiderWebChart) findViewById(R.id.spiderwebchart);
List<TitleValueEntity> data1 = new ArrayList<TitleValueEntity>();
data1.add(new TitleValueEntity(getResources().getString(
R.string.spiderwebchart_title1), 3));//数值越小,对于该标题点的距离就越远
data1.add(new TitleValueEntity(getResources().getString(
R.string.spiderwebchart_title2), 4));
data1.add(new TitleValueEntity(getResources().getString(
R.string.spiderwebchart_title3), 9));
data1.add(new TitleValueEntity(getResources().getString(
R.string.spiderwebchart_title4), 8));
data1.add(new TitleValueEntity(getResources().getString(
R.string.spiderwebchart_title5), 10));
List<TitleValueEntity> data2 = new ArrayList<TitleValueEntity>();
data2.add(new TitleValueEntity(getResources().getString(
R.string.spiderwebchart_title5), 3));
data2.add(new TitleValueEntity(getResources().getString(
R.string.spiderwebchart_title5), 4));
data2.add(new TitleValueEntity(getResources().getString(
R.string.spiderwebchart_title5), 5));
data2.add(new TitleValueEntity(getResources().getString(
R.string.spiderwebchart_title5), 6));
data2.add(new TitleValueEntity(getResources().getString(
R.string.spiderwebchart_title5), 7));
List<List<TitleValueEntity>> data = new ArrayList<List<TitleValueEntity>>();
data.add(data1);//设置两种覆盖区域
data.add(data2);
spiderwebchart.setData(data);
spiderwebchart.setLatitudeNum(5);//蛛网图中织网的圈数
}