package com.example.tests;
import android.app.Activity;
import android.graphics.Color;
import android.graphics.Typeface;
import android.os.Bundle;
import android.util.Log;
import android.view.Window;
import com.github.mikephil.charting.charts.LineChart;
import com.github.mikephil.charting.data.ChartData;
import com.github.mikephil.charting.data.Entry;
import com.github.mikephil.charting.data.LineData;
import com.github.mikephil.charting.data.LineDataSet;
import com.github.mikephil.charting.interfaces.OnChartValueSelectedListener;
import com.github.mikephil.charting.listener.BarLineChartTouchListener;
import com.github.mikephil.charting.utils.Highlight;
import com.github.mikephil.charting.utils.XLabels;
import com.github.mikephil.charting.utils.YLabels;
import com.github.mikephil.charting.utils.XLabels.XLabelPosition;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
public class MainActivity extends Activity implements OnChartValueSelectedListener {
private LineChart mChart;
float x = 0;
float x1 = 0;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.activity_main);
mChart = (LineChart) findViewById(R.id.chart1);
mChart.setOnChartValueSelectedListener(this);
mChart.setDrawYValues(false);// 取消圆点处显示的Y轴值
mChart.setBuleBtn(false);// 禁用蓝色按钮
mChart.setDescription("");// 蓝色按钮旁边的文本
mChart.setGridColor(Color.GREEN);// 网格线的颜色
mChart.setGridWidth(1f);// 网格线的大小
mChart.setGridBackground(new Color().DKGRAY);// 网格背景色
mChart.setxTextColor(Color.BLUE);// 设置x轴字体颜色
mChart.setyTextColor(Color.RED);// 设置y轴字体颜色
Typeface mTf = Typeface.createFromAsset(getAssets(), "OpenSans-Regular.ttf");
XLabels xl = mChart.getXLabels();
xl.setCenterXLabelText(true);
xl.setPosition(XLabelPosition.BOTTOM);// 设置x轴文本显示在下方
xl.setTypeface(mTf);
YLabels yl = mChart.getYLabels();
yl.setTypeface(mTf);
yl.setLabelCount(5);
BarLineChartTouchListener.ismoveY = false;// 是否禁用y抽移动,默认:禁用
BarLineChartTouchListener.isZoomY = false;// 是否禁用y抽缩放,默认:禁用
mChart.setData((LineData) generateDataLine());// 设置数据
mChart.invalidate();
mChart.animateX(1000);// 设置网格动画
// 不要忘记刷新图吗
// holder.chart.invalidate();
// mChart.setStartAtZero(true);
// // 禁用值绘制成图表
// mChart.setDrawYValues(true);
//
// // 使价值凸显
// mChart.setHighlightEnabled(true);
//
// // 支持触控手势
// mChart.setTouchEnabled(true);
//
// // 支持缩放和拖动
// mChart.setDragEnabled(true);
//
// // 如果禁用,扩展可以分别在x,y轴
// mChart.setPinchZoom(false);
// 不要忘记刷新图吗
// holder.chart.invalidate();
// mSeekBarX.setProgress(45);
// mSeekBarY.setProgress(100);
// Legend l = mChart.getLegend();
// l.setPosition(LegendPosition.RIGHT_OF_CHART);
}
@Override
public void onValuesSelected(Entry[] values, Highlight[] highlights,int position) {// 原点点击事件
Log.i("123456", "Value: " values[0].getVal() ", xIndex: " highlights[0].getXIndex() ", DataSet index: " highlights[0].getDataSetIndex());
}
@Override
public void onNothingSelected() {
// TODO Auto-generated method stub
}
private ChartData generateDataLine() {
ArrayList<Entry> e1 = new ArrayList<Entry>();
//第一参数y,第二参数x
e1.add(new Entry((int) (Math.random() * 50), getData("2014-02-28")));
e1.add(new Entry((int) (Math.random() * 50), getData("2014-02-28")));
e1.add(new Entry((int) (Math.random() * 50), getData("2014-02-28")));
e1.add(new Entry((int) (Math.random() * 50), getData("2014-03-12")));
e1.add(new Entry((int) (Math.random() * 50), getData("2014-04-02")));
e1.add(new Entry((int) (Math.random() * 50), getData("2014-05-09")));
e1.add(new Entry((int) (Math.random() * 50), getData("2014-06-15")));
e1.add(new Entry((int) (Math.random() * 50), getData("2014-07-19")));
e1.add(new Entry((int) (Math.random() * 50), getData("2014-08-16")));
e1.add(new Entry((int) (Math.random() * 50), getData("2014-08-23")));
e1.add(new Entry((int) (Math.random() * 50), getData("2014-09-19")));
e1.add(new Entry((int) (Math.random() * 50), getData("2014-10-31")));
e1.add(new Entry((int) (Math.random() * 50), getData("2014-11-26")));
e1.add(new Entry((int) (Math.random() * 50), getData("2014-12-10")));
e1.add(new Entry((int) (Math.random() * 50), getData("2014-12-13")));
Log.d("123456", getData("2014-02-28 1:31:35") "");
Log.d("123456", getData("2014-02-28 5:54:54") "");
Log.d("123456", getData("2014-02-28 18:16:21") "");
Log.d("123456", getData("2014-02-28 23:31:25") "");
Log.d("123456", getData("2014-03-12") "");
Log.d("123456", getData("2014-04-02") "");
Log.d("123456", getData("2014-05-09") "");
Log.d("123456", getData("2014-06-15") "");
Log.d("123456", getData("2014-07-19") "");
Log.d("123456", getData("2014-08-16") "");
Log.d("123456", getData("2014-08-23") "");
Log.d("123456", getData("2014-09-19") "");
Log.d("123456", getData("2014-10-31") "");
Log.d("123456", getData("2014-11-26") "");
Log.d("123456", getData("2014-12-10") "");
Log.d("123456", getData("2014-12-13") "");
LineDataSet d1 = new LineDataSet(e1, "");
d1.setLineWidth(3f);// 线的大小
d1.setColor(Color.WHITE);// 设置有数据在网格里线的颜色
d1.setCircleSize(5f);// 原点大小
d1.setCircleColor(Color.LTGRAY);// 设置原点颜色
ArrayList<LineDataSet> sets = new ArrayList<LineDataSet>();
sets.add(d1);
LineData cd = new LineData(getdateDay(), sets);
return cd;
}
/** 传的数据格式必须是 2010-08-05 12:31:23*/
private float getData(String date) {
String month = date.substring(5, 7);
String day = date.substring(8,10);
boolean b = isLeapYear(Integer.parseInt(date.substring(0, 4)));
float hours = 0;
try {
Date dates = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(date);
hours = (dates.getHours() 1)*0.04f;//换算一天的小时在百分比里面占多少,以每天25个小时计算
} catch (ParseException e) {
e.printStackTrace();
}
if (month.equals("1") || month.equals("01")) {
return Integer.parseInt(day)-1 hours;
} else if (month.equals("2") || month.equals("02")) {
return Integer.parseInt(day) 31 - 1 hours;
} else if (month.equals("3") || month.equals("03")) {
if (b) {
return Integer.parseInt(day) 60-1 hours;
} else {
return Integer.parseInt(day) 59-1 hours;
}
} else if (month.equals("4") || month.equals("04")) {
if (b) {
return Integer.parseInt(day) 91-1 hours;
} else {
return Integer.parseInt(day) 90-1 hours;
}
} else if (month.equals("5") || month.equals("05")) {
if (b) {
return Integer.parseInt(day) 121-1 hours;
} else {
return Integer.parseInt(day) 120-1 hours;
}
} else if (month.equals("6") || month.equals("06")) {
if (b) {
return Integer.parseInt(day) 152-1 hours;
} else {
return Integer.parseInt(day) 151-1 hours;
}
} else if (month.equals("7") || month.equals("07")) {
if (b) {
return Integer.parseInt(day) 182-1 hours;
} else {
return Integer.parseInt(day) 181-1 hours;
}
} else if (month.equals("8") || month.equals("08")) {
if (b) {
return Integer.parseInt(day) 213-1 hours;
} else {
return Integer.parseInt(day) 212-1 hours;
}
} else if (month.equals("9") || month.equals("09")) {
if (b) {
return Integer.parseInt(day) 244-1 hours;
} else {
return Integer.parseInt(day) 243-1 hours;
}
} else if (month.equals("10") || month.equals("10")) {
if (b) {
return Integer.parseInt(day) 274-1 hours;
} else {
return Integer.parseInt(day) 273-1 hours;
}
} else if (month.equals("11") || month.equals("11")) {
if (b) {
return Integer.parseInt(day) 305-1 hours;
} else {
return Integer.parseInt(day) 304-1 hours;
}
} else if (month.equals("12") || month.equals("12")) {
if (b) {
return Integer.parseInt(day) 335-1 hours;
} else {
return Integer.parseInt(day) 334-1 hours;
}
}
return 0;
}
private ArrayList<String> getdateDay() {
ArrayList<String> arraylists = new ArrayList<String>();
Date date = new Date();
for (int j = 1; j <= 31; j ) {
arraylists.add("1-" j);
}
if (isLeapYear((date.getYear() 1900))) {// 判断是否闰年
for (int j = 1; j <= 29; j ) {
arraylists.add("2-" j);
}
} else {
for (int j = 1; j <= 28; j ) {
arraylists.add("2-" j);
}
}
for (int j = 1; j <= 31; j ) {
arraylists.add("3-" j);
}
for (int j = 1; j <= 30; j ) {
arraylists.add("4-" j);
}
for (int j = 1; j <= 31; j ) {
arraylists.add("5-" j);
}
for (int j = 1; j <= 30; j ) {
arraylists.add("6-" j);
}
for (int j = 1; j <= 31; j ) {
arraylists.add("7-" j);
}
for (int j = 1; j <= 31; j ) {
arraylists.add("8-" j);
}
for (int j = 1; j <= 30; j ) {
arraylists.add("9-" j);
}
for (int j = 1; j <= 31; j ) {
arraylists.add("10-" j);
}
for (int j = 1; j <= 30; j ) {
arraylists.add("11-" j);
}
for (int j = 1; j <= 31; j ) {
arraylists.add("12-" j);
}
return arraylists;
}
private boolean isLeapYear(int year) {
if ((year % 400) == 0) {
return true;
}
if ((year % 4) == 0) {
if ((year % 100) == 0) {
return false;
} else {
return true;
}
} else {
return false;
}
}
}
资源文件列表
tests/.classpath , 475
tests/.project , 841
tests/.settings/org.eclipse.jdt.core.prefs , 177
tests/AndroidManifest.xml , 860
tests/assets/OpenSans-Regular.ttf , 217360
tests/bin/AndroidManifest.xml , 860
tests/bin/classes/com/example/tests/BuildConfig.class , 343
tests/bin/classes/com/example/tests/CirclePlanView$1.class , 1201
tests/bin/classes/com/example/tests/CirclePlanView.class , 5597
tests/bin/classes/com/example/tests/imageActivity$1.class , 1169
tests/bin/classes/com/example/tests/imageActivity.class , 1646
tests/bin/classes/com/example/tests/MainActivity.class , 9514
tests/bin/classes/com/example/tests/progressActivity$1.class , 1738
tests/bin/classes/com/example/tests/progressActivity.class , 2109
tests/bin/classes/com/example/tests/ProgressView.class , 2546
tests/bin/classes/com/example/tests/R$anim.class , 390
tests/bin/classes/com/example/tests/R$attr.class , 337
tests/bin/classes/com/example/tests/R$color.class , 1655
tests/bin/classes/com/example/tests/R$dimen.class , 458
tests/bin/classes/com/example/tests/R$drawable.class , 574
tests/bin/classes/com/example/tests/R$id.class , 715
tests/bin/classes/com/example/tests/R$layout.class , 498
tests/bin/classes/com/example/tests/R$menu.class , 385
tests/bin/classes/com/example/tests/R$string.class , 469
tests/bin/classes/com/example/tests/R$style.class , 428
tests/bin/classes/com/example/tests/R.class , 755
tests/bin/classes/com/example/tests/TestDrawActivity.class , 1431
tests/bin/classes/com/github/mikephil/charting/R$color.class , 1688
tests/bin/classes/com/github/mikephil/charting/R$dimen.class , 491
tests/bin/classes/com/github/mikephil/charting/R$drawable.class , 437
tests/bin/classes/com/github/mikephil/charting/R$string.class , 428
tests/bin/classes/com/github/mikephil/charting/R$style.class , 461
tests/bin/classes/com/github/mikephil/charting/R.class , 607
tests/bin/classes.dex , 385164
tests/bin/dexedLibs/mpchartlib-28ef239e922e060af122da917f6da11e.jar , 58618
tests/bin/dexedLibs/nineoldandroids-2.4.0-2-1aa1bb459e9c8ca103e4a8d1106687a2.jar , 44517
tests/bin/dexedLibs/wheel-menu-library-f7b541b274c8b059e25a9f76e7047fe2.jar , 3640
tests/bin/R.txt , 2252
tests/bin/res/crunch/drawable-hdpi/bg_circle_plan.png , 37475
tests/bin/res/crunch/drawable-hdpi/bg_tester.png , 24726
tests/bin/res/crunch/drawable-hdpi/ic_launcher.png , 5964
tests/bin/res/crunch/drawable-hdpi/ic_needle.png , 1179
tests/bin/res/crunch/drawable-hdpi/meter_pointer.png , 392
tests/bin/res/crunch/drawable-mdpi/ic_launcher.png , 3112
tests/bin/res/crunch/drawable-xhdpi/ic_launcher.png , 9355
tests/bin/res/crunch/drawable-xhdpi/wheel.png , 10985
tests/bin/res/crunch/drawable-xxhdpi/ic_launcher.png , 17889
tests/bin/resources.ap_ , 235372
tests/bin/tests.apk , 347776
tests/gen/com/example/tests/BuildConfig.java , 159
tests/gen/com/example/tests/R.java , 7058
tests/gen/com/github/mikephil/charting/R.java , 2749
tests/ic_launcher-web.png , 51394
tests/lint.xml , 53
tests/proguard-project.txt , 781
tests/project.properties , 656
tests/res/anim/animation.xml , 320
tests/res/drawable-hdpi/bg_circle_plan.png , 38707
tests/res/drawable-hdpi/bg_tester.png , 24726
tests/res/drawable-hdpi/ic_launcher.png , 7658
tests/res/drawable-hdpi/ic_needle.png , 1179
tests/res/drawable-hdpi/meter_pointer.png , 3358
tests/res/drawable-mdpi/ic_launcher.png , 3777
tests/res/drawable-xhdpi/ic_launcher.png , 12516
tests/res/drawable-xhdpi/wheel.png , 18807
tests/res/drawable-xxhdpi/ic_launcher.png , 24777
tests/res/layout/activity_main.xml , 460
tests/res/layout/image_activity.xml , 1103
tests/res/layout/progress.xml , 835
tests/res/layout/test.xml , 1418
tests/res/menu/main.xml , 367
tests/res/values/dimens.xml , 220
tests/res/values/strings.xml , 222
tests/res/values/styles.xml , 697
tests/res/values-v11/styles.xml , 334
tests/res/values-v14/styles.xml , 391
tests/res/values-w820dp/dimens.xml , 381
tests/src/com/example/tests/CirclePlanView.java , 4675
tests/src/com/example/tests/imageActivity.java , 988
tests/src/com/example/tests/MainActivity.java , 9881
tests/src/com/example/tests/progressActivity.java , 1451
tests/src/com/example/tests/ProgressView.java , 1829
tests/src/com/example/tests/TestDrawActivity.java , 1284
