|
|
|
@ -1,15 +1,31 @@ |
|
|
|
package com.qhclh.ytzh.work.breedpoultry; |
|
|
|
|
|
|
|
import android.content.Intent; |
|
|
|
import android.graphics.Color; |
|
|
|
import android.support.v7.widget.Toolbar; |
|
|
|
import android.view.Menu; |
|
|
|
import android.view.MenuItem; |
|
|
|
import android.view.View; |
|
|
|
import android.widget.TextView; |
|
|
|
|
|
|
|
import com.qhclh.ytzh.R; |
|
|
|
import com.qhclh.ytzh.base.BaseActivity; |
|
|
|
|
|
|
|
import java.util.ArrayList; |
|
|
|
import java.util.List; |
|
|
|
|
|
|
|
import butterknife.BindView; |
|
|
|
import lecho.lib.hellocharts.formatter.LineChartValueFormatter; |
|
|
|
import lecho.lib.hellocharts.formatter.SimpleLineChartValueFormatter; |
|
|
|
import lecho.lib.hellocharts.gesture.ZoomType; |
|
|
|
import lecho.lib.hellocharts.model.Axis; |
|
|
|
import lecho.lib.hellocharts.model.AxisValue; |
|
|
|
import lecho.lib.hellocharts.model.Line; |
|
|
|
import lecho.lib.hellocharts.model.LineChartData; |
|
|
|
import lecho.lib.hellocharts.model.PointValue; |
|
|
|
import lecho.lib.hellocharts.model.ValueShape; |
|
|
|
import lecho.lib.hellocharts.model.Viewport; |
|
|
|
import lecho.lib.hellocharts.view.LineChartView; |
|
|
|
|
|
|
|
/** |
|
|
|
* Created by 青花瓷 on 2017/11/30. |
|
|
|
@ -18,6 +34,28 @@ import butterknife.BindView; |
|
|
|
public class DatanalysisActivity extends BaseActivity { |
|
|
|
@BindView(R.id.toolbar) |
|
|
|
Toolbar mToolbar; |
|
|
|
@BindView(R.id.taget_content1) |
|
|
|
TextView taget_content1; |
|
|
|
@BindView(R.id.line_chart) |
|
|
|
LineChartView lineChart; |
|
|
|
|
|
|
|
///< 横坐标 |
|
|
|
private List<AxisValue> mAxisXValuesList = new ArrayList<AxisValue>(); |
|
|
|
///< 横坐标 |
|
|
|
List<String> hengzuobiaolist = new ArrayList<>(); |
|
|
|
String[] date;//X轴的标注 |
|
|
|
///< 指标数据 |
|
|
|
private List<PointValue> mPointValuesList = new ArrayList<PointValue>(); |
|
|
|
///< 基准线 标准线 |
|
|
|
private List<PointValue> mPointValuesList1 = new ArrayList<PointValue>(); |
|
|
|
|
|
|
|
///< 指标数据 |
|
|
|
List listshuju = new ArrayList(); |
|
|
|
Float[] score;//图表的数据 |
|
|
|
///< 基准线数据 |
|
|
|
Float[] score1; |
|
|
|
///< 获取到的基准线值 |
|
|
|
private List listjizhun = new ArrayList(); |
|
|
|
@Override |
|
|
|
protected int setLayoutId() { |
|
|
|
return R.layout.act_datanalysis; |
|
|
|
@ -35,7 +73,28 @@ public class DatanalysisActivity extends BaseActivity { |
|
|
|
|
|
|
|
@Override |
|
|
|
protected void initData() { |
|
|
|
taget_content1.setText("20\t\t10\t\t15"); |
|
|
|
for (int i=0;i<7;i++){ |
|
|
|
hengzuobiaolist.add("第"+i+"天"); |
|
|
|
listshuju.add(i+1.0f); |
|
|
|
listjizhun.add(i+2.0f); |
|
|
|
} |
|
|
|
|
|
|
|
///< 横坐标数据 |
|
|
|
int lenth = hengzuobiaolist.size(); |
|
|
|
date = hengzuobiaolist.toArray(new String[lenth]); |
|
|
|
|
|
|
|
///< 批次数据 |
|
|
|
int length = listshuju.size(); |
|
|
|
score = (Float[]) listshuju.toArray(new Float[length]); |
|
|
|
|
|
|
|
///< 基准 标准 |
|
|
|
int size = listjizhun.size(); |
|
|
|
score1 = (Float[]) listjizhun.toArray(new Float[size]); |
|
|
|
|
|
|
|
getAxisXLables();//获取x轴的标注 |
|
|
|
getAxisPoints();//获取坐标点 |
|
|
|
initLineChart();//初始化 |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
@ -60,4 +119,106 @@ public class DatanalysisActivity extends BaseActivity { |
|
|
|
} |
|
|
|
return super.onOptionsItemSelected(item); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* X 轴的显示 |
|
|
|
*/ |
|
|
|
private void getAxisXLables() { |
|
|
|
mAxisXValuesList.clear(); |
|
|
|
for (int i = 0; i < date.length; i++) { |
|
|
|
mAxisXValuesList.add(new AxisValue(i).setLabel(date[i])); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 图表的每个点的显示 |
|
|
|
*/ |
|
|
|
private void getAxisPoints() { |
|
|
|
mPointValuesList.clear(); |
|
|
|
mPointValuesList1.clear(); |
|
|
|
for (int i = 0; i < score.length; i++) { |
|
|
|
mPointValuesList.add(new PointValue(i, score[i])); |
|
|
|
} |
|
|
|
for (int i = 0; i < score1.length; i++) { |
|
|
|
mPointValuesList1.add(new PointValue(i, score1[i])); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 初始化LineChart的一些设置 |
|
|
|
*/ |
|
|
|
private void initLineChart() { |
|
|
|
///< 数据 |
|
|
|
Line line = new Line(mPointValuesList).setColor(Color.parseColor("#336699")); //折线的颜色 |
|
|
|
///< 标准线 |
|
|
|
Line line1 = new Line(mPointValuesList1).setColor(Color.parseColor("#2eab71")); //折线的颜色 |
|
|
|
List<Line> lines = new ArrayList<Line>(); |
|
|
|
|
|
|
|
line.setShape(ValueShape.CIRCLE);//折线图上每个数据点的形状 这里是圆形 (有三种 :ValueShape.SQUARE ValueShape.CIRCLE ValueShape.DIAMOND) |
|
|
|
line1.setShape(ValueShape.CIRCLE);//折线图上每个数据点的形状 这里是圆形 (有三种 :ValueShape.SQUARE ValueShape.CIRCLE ValueShape.DIAMOND) |
|
|
|
line.setCubic(false);//曲线是否平滑 |
|
|
|
line1.setCubic(false);//曲线是否平滑 |
|
|
|
// line.setStrokeWidth(3);//线条的粗细,默认是3 |
|
|
|
line1.setStrokeWidth(1);//线条的粗细,默认是3 |
|
|
|
line.setFilled(false);//是否填充曲线的面积 |
|
|
|
line1.setFilled(false);//是否填充曲线的面积 |
|
|
|
line.setHasLabels(true);//曲线的数据坐标是否加上备注 |
|
|
|
line1.setHasLabels(false);//曲线的数据坐标是否加上备注 |
|
|
|
// line.setHasLabelsOnlyForSelected(true);//点击数据坐标提示数据(设置了这个line.setHasLabels(true);就无效) |
|
|
|
line.setHasLines(true);//是否用直线显示。如果为false 则没有曲线只有点显示 |
|
|
|
line1.setHasLines(true);//是否用直线显示。如果为false 则没有曲线只有点显示 |
|
|
|
line.setHasPoints(true);//是否显示圆点 如果为false 则没有原点只有点显示 |
|
|
|
line1.setHasPoints(false);//是否显示圆点 如果为false 则没有原点只有点显示 |
|
|
|
LineChartValueFormatter chartValueFormatter = new SimpleLineChartValueFormatter(2); |
|
|
|
line.setFormatter(chartValueFormatter);//显示小数点 |
|
|
|
line1.setFormatter(chartValueFormatter);//显示小数点 |
|
|
|
lines.add(line); |
|
|
|
lines.add(line1); |
|
|
|
LineChartData data = new LineChartData(); |
|
|
|
data.setLines(lines); |
|
|
|
|
|
|
|
//坐标轴 |
|
|
|
Axis axisX = new Axis(); //X轴 |
|
|
|
axisX.setHasTiltedLabels(false); //X轴下面坐标轴字体是斜的显示还是直的,true是斜的显示 |
|
|
|
axisX.setTextColor(Color.WHITE); //设置字体颜色 |
|
|
|
axisX.setTextColor(Color.parseColor("#336699"));//灰色 |
|
|
|
|
|
|
|
|
|
|
|
// axisX.setName(hengzuobiao); //表格名称 |
|
|
|
axisX.setTextSize(11);//设置字体大小 |
|
|
|
axisX.setMaxLabelChars(6); //最多几个X轴坐标,意思就是你的缩放让X轴上数据的个数7<=x<=mAxisValues.length |
|
|
|
axisX.setValues(mAxisXValuesList); //填充X轴的坐标名称 |
|
|
|
data.setAxisXBottom(axisX); //x 轴在底部 |
|
|
|
//// data.setAxisXTop(axisX); //x 轴在顶部 |
|
|
|
// axisX.setHasLines(true); //x 轴分割线 |
|
|
|
// |
|
|
|
// |
|
|
|
Axis axisY = new Axis(); //Y轴 |
|
|
|
// axisY.setName(zongzuobiao);//y轴标注 |
|
|
|
axisY.setTextSize(11);//设置字体大小 |
|
|
|
data.setAxisYLeft(axisY); //Y轴设置在左边 |
|
|
|
//data.setAxisYRight(axisY); //y轴设置在右边 |
|
|
|
|
|
|
|
//设置行为属性,支持缩放、滑动以及平移 |
|
|
|
lineChart.setInteractive(true); |
|
|
|
lineChart.setZoomType(ZoomType.HORIZONTAL); //缩放类型,水平 |
|
|
|
lineChart.setMaxZoom((float) 10);//缩放比例 |
|
|
|
lineChart.setLineChartData(data); |
|
|
|
lineChart.setVisibility(View.VISIBLE); |
|
|
|
/**注:下面的7,10只是代表一个数字去类比而已 |
|
|
|
* 尼玛搞的老子好辛苦!!!见(http://forum.xda-developers.com/tools/programming/library-hellocharts-charting-library-t2904456/page2); |
|
|
|
* 下面几句可以设置X轴数据的显示个数(x轴0-7个数据),当数据点个数小于(29)的时候,缩小到极致hellochart默认的是所有显示。当数据点个数大于(29)的时候, |
|
|
|
* 若不设置axisX.setMaxLabelChars(int count)这句话,则会自动适配X轴所能显示的尽量合适的数据个数。 |
|
|
|
* 若设置axisX.setMaxLabelChars(int count)这句话, |
|
|
|
* 33个数据点测试,若 axisX.setMaxLabelChars(10);里面的10大于v.right= 7; 里面的7,则 |
|
|
|
刚开始X轴显示7条数据,然后缩放的时候X轴的个数会保证大于7小于10 |
|
|
|
若小于v.right= 7;中的7,反正我感觉是这两句都好像失效了的样子 - -! |
|
|
|
* 并且Y轴是根据数据的大小自动设置Y轴上限 |
|
|
|
* 若这儿不设置 v.right= 7; 这句话,则图表刚开始就会尽可能的显示所有数据,交互性太差 |
|
|
|
*/ |
|
|
|
Viewport v = new Viewport(lineChart.getMaximumViewport()); |
|
|
|
v.left = 0; |
|
|
|
v.right = 6; |
|
|
|
lineChart.setCurrentViewport(v); |
|
|
|
} |
|
|
|
} |