|
|
|
@ -1,5 +1,6 @@ |
|
|
|
package com.qhclh.ytzh.work.Poultrydailyreport; |
|
|
|
|
|
|
|
import android.graphics.Color; |
|
|
|
import android.support.v7.widget.Toolbar; |
|
|
|
import android.view.View; |
|
|
|
import android.widget.LinearLayout; |
|
|
|
@ -7,13 +8,29 @@ import android.widget.TextView; |
|
|
|
|
|
|
|
import com.qhclh.ytzh.R; |
|
|
|
import com.qhclh.ytzh.base.BaseActivity; |
|
|
|
import com.qhclh.ytzh.home.RpcUrl; |
|
|
|
import com.qhclh.ytzh.tasks.ViewOnClickTask; |
|
|
|
|
|
|
|
import org.forks.jsonrpc.JsonRpcResult; |
|
|
|
import org.forks.jsonrpc.RpcFacade; |
|
|
|
import org.json.JSONArray; |
|
|
|
import org.json.JSONException; |
|
|
|
|
|
|
|
import java.util.ArrayList; |
|
|
|
import java.util.List; |
|
|
|
|
|
|
|
import butterknife.BindView; |
|
|
|
import butterknife.OnClick; |
|
|
|
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; |
|
|
|
|
|
|
|
/** |
|
|
|
@ -46,6 +63,8 @@ public class PoultryDataChartActivity extends BaseActivity { |
|
|
|
List<String> hengzuobiaolist = new ArrayList<>(); |
|
|
|
String[] date;//X轴的标注 |
|
|
|
|
|
|
|
///< 指标数据 |
|
|
|
private List<PointValue> mPointValuesList = new ArrayList<PointValue>(); |
|
|
|
///< 指标数据 |
|
|
|
List listshuju = new ArrayList(); |
|
|
|
Float[] score;//图表的数据 |
|
|
|
@ -86,10 +105,6 @@ public class PoultryDataChartActivity extends BaseActivity { |
|
|
|
HouseView("母死淘","#da4848"); |
|
|
|
} |
|
|
|
|
|
|
|
private void HouseView(final String item, final String color) { |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
@OnClick({R.id.ll_musitao, R.id.ll_muzhiliaoliang, R.id.ll_chandanlv}) |
|
|
|
public void OnClick(View view){ |
|
|
|
switch (view.getId()){ |
|
|
|
@ -106,4 +121,131 @@ public class PoultryDataChartActivity extends BaseActivity { |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private void HouseView(final String item, final String color) { |
|
|
|
ViewOnClickTask HouseViewTask = new ViewOnClickTask(this,"加载中...") { |
|
|
|
List<String> rpobj; |
|
|
|
@Override |
|
|
|
protected void successUI() { |
|
|
|
String js = rpobj.toString(); |
|
|
|
hengzuobiaolist.clear(); |
|
|
|
listshuju.clear(); |
|
|
|
try { |
|
|
|
JSONArray jsonArray = new JSONArray(js); |
|
|
|
for (int i=0;i<jsonArray.length();i++){ |
|
|
|
JSONArray jsArray = jsonArray.getJSONArray(i); |
|
|
|
hengzuobiaolist.add("第"+jsArray.get(0)+"日龄"); |
|
|
|
listshuju.add(Float.parseFloat(jsArray.get(1).toString())); |
|
|
|
} |
|
|
|
|
|
|
|
} catch (JSONException e) { |
|
|
|
e.printStackTrace(); |
|
|
|
} |
|
|
|
|
|
|
|
///< 横坐标数据 |
|
|
|
int lenth = hengzuobiaolist.size(); |
|
|
|
date = hengzuobiaolist.toArray(new String[lenth]); |
|
|
|
|
|
|
|
///< 批次数据 |
|
|
|
int length = listshuju.size(); |
|
|
|
score = (Float[]) listshuju.toArray(new Float[length]); |
|
|
|
|
|
|
|
getAxisXLables();//获取x轴的标注 |
|
|
|
getAxisPoints();//获取坐标点 |
|
|
|
initLineChart(color);//初始化 |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public Object call() throws Exception { |
|
|
|
JsonRpcResult result = RpcFacade.rpcCall(RpcUrl.HouseView1,House_ID,item); |
|
|
|
rpobj = result.getStringList(); |
|
|
|
return null; |
|
|
|
} |
|
|
|
}; |
|
|
|
HouseViewTask.execute(); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
* 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(); |
|
|
|
for (int i = 0; i < score.length; i++) { |
|
|
|
mPointValuesList.add(new PointValue(i, score[i])); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 初始化LineChart的一些设置 |
|
|
|
*/ |
|
|
|
private void initLineChart(String color) { |
|
|
|
///< 数据 |
|
|
|
Line line = new Line(mPointValuesList).setColor(Color.parseColor(color)); //折线的颜色 |
|
|
|
|
|
|
|
List<Line> lines = new ArrayList<Line>(); |
|
|
|
|
|
|
|
line.setShape(ValueShape.CIRCLE);//折线图上每个数据点的形状 这里是圆形 (有三种 :ValueShape.SQUARE ValueShape.CIRCLE ValueShape.DIAMOND) |
|
|
|
line.setCubic(false);//曲线是否平滑 |
|
|
|
line.setStrokeWidth(2);//线条的粗细,默认是3 |
|
|
|
line.setFilled(false);//是否填充曲线的面积 |
|
|
|
line.setHasLabels(true);//曲线的数据坐标是否加上备注 |
|
|
|
line.setHasLines(true);//是否用直线显示。如果为false 则没有曲线只有点显示 |
|
|
|
line.setHasPoints(true);//是否显示圆点 如果为false 则没有原点只有点显示 |
|
|
|
LineChartValueFormatter chartValueFormatter = new SimpleLineChartValueFormatter(2); |
|
|
|
line.setFormatter(chartValueFormatter);//显示小数点 |
|
|
|
lines.add(line); |
|
|
|
LineChartData data = new LineChartData(); |
|
|
|
data.setLines(lines); |
|
|
|
|
|
|
|
//坐标轴 |
|
|
|
Axis axisX = new Axis(); //X轴 |
|
|
|
axisX.setHasTiltedLabels(false); //X轴下面坐标轴字体是斜的显示还是直的,true是斜的显示 |
|
|
|
axisX.setTextColor(Color.parseColor("#336699")); |
|
|
|
|
|
|
|
|
|
|
|
axisX.setTextSize(11);//设置字体大小 |
|
|
|
axisX.setMaxLabelChars(6); //最多几个X轴坐标,意思就是你的缩放让X轴上数据的个数7<=x<=mAxisValues.length |
|
|
|
axisX.setValues(mAxisXValuesList); //填充X轴的坐标名称 |
|
|
|
data.setAxisXBottom(axisX); //x 轴在底部 |
|
|
|
|
|
|
|
|
|
|
|
Axis axisY = new Axis(); //Y轴 |
|
|
|
axisY.setTextSize(11);//设置字体大小 |
|
|
|
axisY.setTextColor(Color.parseColor("#336699")); |
|
|
|
data.setAxisYLeft(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); |
|
|
|
} |
|
|
|
} |