|
|
|
@ -73,8 +73,12 @@ public class DeviceAlarmInfoLineChartActivity extends BaseViewBindingActivity<Ac
|
|
|
|
SimpleDateFormat sdfDay = new SimpleDateFormat("yyyy-MM-dd");
|
|
|
|
SimpleDateFormat sdfDay = new SimpleDateFormat("yyyy-MM-dd");
|
|
|
|
SimpleDateFormat sdfHourMinute = new SimpleDateFormat("HH:mm");
|
|
|
|
SimpleDateFormat sdfHourMinute = new SimpleDateFormat("HH:mm");
|
|
|
|
private List<DeviceAlarmInfoLineChartBean.DeviceVibrationMonitoringData> deviceAlarmDataList = new ArrayList<>();
|
|
|
|
private List<DeviceAlarmInfoLineChartBean.DeviceVibrationMonitoringData> deviceAlarmDataList = new ArrayList<>();
|
|
|
|
|
|
|
|
private double maxTemperature=0;
|
|
|
|
|
|
|
|
private double maxAddSpeed=0;
|
|
|
|
|
|
|
|
|
|
|
|
private ArrayList<String> xlabellistdatas = new ArrayList<>();;
|
|
|
|
private ArrayList<String> xLabelListData = new ArrayList<>();
|
|
|
|
|
|
|
|
private ArrayList<String> xLabelListDataAddSpeed = new ArrayList<>();
|
|
|
|
|
|
|
|
private ArrayList<String> xLabelListDataSpeed = new ArrayList<>();
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
protected ActivityDeviceAlarmInfoLineChartBinding getBinding() {
|
|
|
|
protected ActivityDeviceAlarmInfoLineChartBinding getBinding() {
|
|
|
|
@ -115,6 +119,10 @@ public class DeviceAlarmInfoLineChartActivity extends BaseViewBindingActivity<Ac
|
|
|
|
calendar.setTime(date);
|
|
|
|
calendar.setTime(date);
|
|
|
|
DateTimeMinutePickDialog dialog = new DateTimeMinutePickDialog(context, calendar, true,true, (outPutDate, outPutDate1, outPutDate2) -> {
|
|
|
|
DateTimeMinutePickDialog dialog = new DateTimeMinutePickDialog(context, calendar, true,true, (outPutDate, outPutDate1, outPutDate2) -> {
|
|
|
|
binding.tvSt.setText(outPutDate+":00");
|
|
|
|
binding.tvSt.setText(outPutDate+":00");
|
|
|
|
|
|
|
|
if(deviceCode!=null){
|
|
|
|
|
|
|
|
showLog(deviceCode);
|
|
|
|
|
|
|
|
getDeviceAlarmInfoLineChartData();
|
|
|
|
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
dialog.show();
|
|
|
|
dialog.show();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@ -130,6 +138,10 @@ public class DeviceAlarmInfoLineChartActivity extends BaseViewBindingActivity<Ac
|
|
|
|
calendar.setTime(date);
|
|
|
|
calendar.setTime(date);
|
|
|
|
DateTimeMinutePickDialog dialog = new DateTimeMinutePickDialog(context, calendar, true,true, (outPutDate, outPutDate1, outPutDate2) -> {
|
|
|
|
DateTimeMinutePickDialog dialog = new DateTimeMinutePickDialog(context, calendar, true,true, (outPutDate, outPutDate1, outPutDate2) -> {
|
|
|
|
binding.tvEt.setText(outPutDate+":59");
|
|
|
|
binding.tvEt.setText(outPutDate+":59");
|
|
|
|
|
|
|
|
if(deviceCode!=null){
|
|
|
|
|
|
|
|
showLog(deviceCode);
|
|
|
|
|
|
|
|
getDeviceAlarmInfoLineChartData();
|
|
|
|
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
dialog.show();
|
|
|
|
dialog.show();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@ -169,6 +181,7 @@ public class DeviceAlarmInfoLineChartActivity extends BaseViewBindingActivity<Ac
|
|
|
|
binding.rb5.setChecked(false);
|
|
|
|
binding.rb5.setChecked(false);
|
|
|
|
binding.rb6.setChecked(false);
|
|
|
|
binding.rb6.setChecked(false);
|
|
|
|
binding.rb7.setChecked(false);
|
|
|
|
binding.rb7.setChecked(false);
|
|
|
|
|
|
|
|
renderTemperature();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
binding.rb2.setOnCheckedChangeListener((buttonView, isChecked) -> {
|
|
|
|
binding.rb2.setOnCheckedChangeListener((buttonView, isChecked) -> {
|
|
|
|
@ -180,6 +193,7 @@ public class DeviceAlarmInfoLineChartActivity extends BaseViewBindingActivity<Ac
|
|
|
|
binding.rb5.setChecked(false);
|
|
|
|
binding.rb5.setChecked(false);
|
|
|
|
binding.rb6.setChecked(false);
|
|
|
|
binding.rb6.setChecked(false);
|
|
|
|
binding.rb7.setChecked(false);
|
|
|
|
binding.rb7.setChecked(false);
|
|
|
|
|
|
|
|
renderAddSpeed();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
binding.rb3.setOnCheckedChangeListener((buttonView, isChecked) -> {
|
|
|
|
binding.rb3.setOnCheckedChangeListener((buttonView, isChecked) -> {
|
|
|
|
@ -260,26 +274,15 @@ public class DeviceAlarmInfoLineChartActivity extends BaseViewBindingActivity<Ac
|
|
|
|
deviceAlarmDataList.clear();
|
|
|
|
deviceAlarmDataList.clear();
|
|
|
|
deviceAlarmDataList.addAll(bean.getData());
|
|
|
|
deviceAlarmDataList.addAll(bean.getData());
|
|
|
|
//Collections.reverse(deviceAlarmDataList);
|
|
|
|
//Collections.reverse(deviceAlarmDataList);
|
|
|
|
List<Entry> entries1 = new ArrayList<>();
|
|
|
|
if(binding.rb1.isChecked()){
|
|
|
|
for (int i = 0; i < deviceAlarmDataList.size(); i++) {
|
|
|
|
renderTemperature();
|
|
|
|
try {
|
|
|
|
}
|
|
|
|
DeviceAlarmInfoLineChartBean.DeviceVibrationMonitoringData item = deviceAlarmDataList.get(i);
|
|
|
|
if(binding.rb2.isChecked()){
|
|
|
|
entries1.add(new Entry(i, Float.parseFloat(item.getTemperature().toString())));
|
|
|
|
renderAddSpeed();
|
|
|
|
|
|
|
|
|
|
|
|
Date date = sdf.parse(item.getDeviceTime());
|
|
|
|
|
|
|
|
if(date != null){
|
|
|
|
|
|
|
|
Calendar calendar = Calendar.getInstance();
|
|
|
|
|
|
|
|
calendar.setTime(date);
|
|
|
|
|
|
|
|
xlabellistdatas.add(sdfHourMinute.format(calendar.getTime()));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} catch (ParseException e) {
|
|
|
|
|
|
|
|
throw new RuntimeException(e);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
showLog(String.valueOf(deviceAlarmDataList.size()));
|
|
|
|
|
|
|
|
setDatas(entries1);
|
|
|
|
|
|
|
|
}else{
|
|
|
|
}else{
|
|
|
|
showLog("is emply");
|
|
|
|
showLog("is emply");
|
|
|
|
|
|
|
|
setDes();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@ -289,6 +292,56 @@ public class DeviceAlarmInfoLineChartActivity extends BaseViewBindingActivity<Ac
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void renderTemperature(){
|
|
|
|
|
|
|
|
xLabelListData.clear();
|
|
|
|
|
|
|
|
maxTemperature=0;
|
|
|
|
|
|
|
|
List<Entry> entries1 = new ArrayList<>();
|
|
|
|
|
|
|
|
for (int i = 0; i < deviceAlarmDataList.size(); i++) {
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
DeviceAlarmInfoLineChartBean.DeviceVibrationMonitoringData item = deviceAlarmDataList.get(i);
|
|
|
|
|
|
|
|
entries1.add(new Entry(i, Float.parseFloat(item.getTemperature().toString())));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Date date = sdf.parse(item.getDeviceTime());
|
|
|
|
|
|
|
|
if(date != null){
|
|
|
|
|
|
|
|
Calendar calendar = Calendar.getInstance();
|
|
|
|
|
|
|
|
calendar.setTime(date);
|
|
|
|
|
|
|
|
xLabelListData.add(sdfHourMinute.format(calendar.getTime()));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if(item.getTemperature()!=null&& item.getTemperature() >maxTemperature){
|
|
|
|
|
|
|
|
maxTemperature=item.getTemperature();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} catch (ParseException e) {
|
|
|
|
|
|
|
|
throw new RuntimeException(e);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
showLog(String.valueOf(deviceAlarmDataList.size()));
|
|
|
|
|
|
|
|
showLog("maxTemperature:"+String.valueOf(maxTemperature));
|
|
|
|
|
|
|
|
if(maxTemperature<20){
|
|
|
|
|
|
|
|
maxTemperature=30;
|
|
|
|
|
|
|
|
}else if(maxTemperature>=20&&maxTemperature<30){
|
|
|
|
|
|
|
|
maxTemperature=40;
|
|
|
|
|
|
|
|
}else if(maxTemperature>=30&&maxTemperature<40){
|
|
|
|
|
|
|
|
maxTemperature=50;
|
|
|
|
|
|
|
|
}else if(maxTemperature>=40&&maxTemperature<50){
|
|
|
|
|
|
|
|
maxTemperature=60;
|
|
|
|
|
|
|
|
}else if(maxTemperature>=50&&maxTemperature<60){
|
|
|
|
|
|
|
|
maxTemperature=70;
|
|
|
|
|
|
|
|
}else if(maxTemperature>=60&&maxTemperature<70){
|
|
|
|
|
|
|
|
maxTemperature=80;
|
|
|
|
|
|
|
|
}else if(maxTemperature>=70&&maxTemperature<80){
|
|
|
|
|
|
|
|
maxTemperature=90;
|
|
|
|
|
|
|
|
}else if(maxTemperature>=80&&maxTemperature<90){
|
|
|
|
|
|
|
|
maxTemperature=100;
|
|
|
|
|
|
|
|
}else if(maxTemperature>=90&&maxTemperature<100){
|
|
|
|
|
|
|
|
maxTemperature=110;
|
|
|
|
|
|
|
|
}else{
|
|
|
|
|
|
|
|
maxTemperature=maxTemperature+10;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
showLog("maxTemperature:"+String.valueOf(maxTemperature));
|
|
|
|
|
|
|
|
setDataTemperature(entries1);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
//初始化折线图
|
|
|
|
private void setDes() {
|
|
|
|
private void setDes() {
|
|
|
|
Description description = new Description();
|
|
|
|
Description description = new Description();
|
|
|
|
description.setText("");
|
|
|
|
description.setText("");
|
|
|
|
@ -306,23 +359,49 @@ public class DeviceAlarmInfoLineChartActivity extends BaseViewBindingActivity<Ac
|
|
|
|
binding.linechart.setExtraBottomOffset(20f);
|
|
|
|
binding.linechart.setExtraBottomOffset(20f);
|
|
|
|
binding.linechart.setExtraRightOffset(30f);
|
|
|
|
binding.linechart.setExtraRightOffset(30f);
|
|
|
|
binding.linechart.setExtraLeftOffset(10f);
|
|
|
|
binding.linechart.setExtraLeftOffset(10f);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 方法一:通过设置 X 轴偏移量间接控制
|
|
|
|
|
|
|
|
// legend.setXEntrySpace(10f); // 条目之间的水平间距
|
|
|
|
|
|
|
|
// legend.setYEntrySpace(10f); // 行之间的垂直间距
|
|
|
|
|
|
|
|
// legend.setFormSize(10f); // 图例图标大小
|
|
|
|
|
|
|
|
// // 启用自动换行
|
|
|
|
|
|
|
|
// legend.setWordWrapEnabled(true);
|
|
|
|
|
|
|
|
// // 设置换行策略
|
|
|
|
|
|
|
|
// legend.setDirection(Legend.LegendDirection.LEFT_TO_RIGHT);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//方法二:基本多行显示配置
|
|
|
|
|
|
|
|
// 水平方向排列
|
|
|
|
|
|
|
|
//legend.setOrientation(Legend.LegendOrientation.VERTICAL);
|
|
|
|
|
|
|
|
// 垂直方向排列
|
|
|
|
|
|
|
|
legend.setOrientation(Legend.LegendOrientation.HORIZONTAL);
|
|
|
|
|
|
|
|
// 设置在底部居中
|
|
|
|
|
|
|
|
legend.setVerticalAlignment(Legend.LegendVerticalAlignment.BOTTOM);
|
|
|
|
|
|
|
|
legend.setHorizontalAlignment(Legend.LegendHorizontalAlignment.LEFT);
|
|
|
|
|
|
|
|
// 启用自动换行
|
|
|
|
|
|
|
|
legend.setWordWrapEnabled(true);
|
|
|
|
|
|
|
|
legend.setFormSize(10f); // 图例图标大小
|
|
|
|
}
|
|
|
|
}
|
|
|
|
private void setDatas(List<Entry> datas) {
|
|
|
|
private void setDataTemperature(List<Entry> datas) {
|
|
|
|
|
|
|
|
// 清除所有数据
|
|
|
|
|
|
|
|
binding.linechart.clear();
|
|
|
|
|
|
|
|
binding.linechart.invalidate(); // 重绘视图
|
|
|
|
|
|
|
|
|
|
|
|
String deviceNameLine = deviceName+"温度";
|
|
|
|
String deviceNameLine = deviceName+"温度";
|
|
|
|
List<ILineDataSet> sets = new ArrayList<>();
|
|
|
|
List<ILineDataSet> sets = new ArrayList<>();
|
|
|
|
LineDataSet dataSet1 = new LineDataSet(datas, deviceNameLine);
|
|
|
|
LineDataSet dataSet1 = new LineDataSet(datas, deviceNameLine);
|
|
|
|
dataSet1.setValueTextSize(12);
|
|
|
|
dataSet1.setValueTextSize(12);
|
|
|
|
dataSet1.setValueTextColor(Color.parseColor("#FC863E"));
|
|
|
|
dataSet1.setValueTextColor(Color.parseColor("#FC863E"));
|
|
|
|
dataSet1.setMode(LineDataSet.Mode.CUBIC_BEZIER);
|
|
|
|
dataSet1.setMode(LineDataSet.Mode.CUBIC_BEZIER);
|
|
|
|
dataSet1.setLineWidth(1);
|
|
|
|
dataSet1.setLineWidth(2);
|
|
|
|
dataSet1.setCircleHoleRadius(4);
|
|
|
|
dataSet1.setCircleHoleRadius(3);
|
|
|
|
dataSet1.enableDashedLine(5, 5, 0);
|
|
|
|
//dataSet1.enableDashedLine(5, 5, 0);
|
|
|
|
dataSet1.setCircleColor(Color.parseColor("#FC863E"));
|
|
|
|
dataSet1.setCircleColor(Color.parseColor("#FC863E"));
|
|
|
|
dataSet1.setColor(Color.parseColor("#FC863E"));
|
|
|
|
dataSet1.setColor(Color.parseColor("#FC863E"));
|
|
|
|
dataSet1.setDrawHighlightIndicators(false);
|
|
|
|
dataSet1.setDrawHighlightIndicators(false);
|
|
|
|
dataSet1.setDrawFilled(true);
|
|
|
|
dataSet1.setDrawFilled(true);
|
|
|
|
dataSet1.setFillDrawable(new GradientDrawable(GradientDrawable.Orientation.TOP_BOTTOM, new int[]{Color.argb(127, 235, 170, 106), Color.parseColor("#00FA5544")}));
|
|
|
|
dataSet1.setFillDrawable(new GradientDrawable(GradientDrawable.Orientation.TOP_BOTTOM, new int[]{Color.argb(127, 235, 170, 106), Color.parseColor("#00FA5544")}));
|
|
|
|
dataSet1.setLineWidth(1);
|
|
|
|
dataSet1.setLineWidth(2);
|
|
|
|
dataSet1.setDrawValues(false);
|
|
|
|
dataSet1.setDrawValues(false);
|
|
|
|
|
|
|
|
|
|
|
|
sets.add(dataSet1);
|
|
|
|
sets.add(dataSet1);
|
|
|
|
@ -339,7 +418,7 @@ public class DeviceAlarmInfoLineChartActivity extends BaseViewBindingActivity<Ac
|
|
|
|
xAxis.setDrawGridLines(true);//是否设置x轴上每个点对应的线 即 竖向的网格线
|
|
|
|
xAxis.setDrawGridLines(true);//是否设置x轴上每个点对应的线 即 竖向的网格线
|
|
|
|
xAxis.enableGridDashedLine(2, 2, 2); //竖线 虚线样式 lineLength控制虚线段的长度 spaceLength控制线之间的空间
|
|
|
|
xAxis.enableGridDashedLine(2, 2, 2); //竖线 虚线样式 lineLength控制虚线段的长度 spaceLength控制线之间的空间
|
|
|
|
xAxis.setLabelRotationAngle(40f);//设置x轴标签的旋转角度
|
|
|
|
xAxis.setLabelRotationAngle(40f);//设置x轴标签的旋转角度
|
|
|
|
String[] timearray = xlabellistdatas.toArray(new String[xlabellistdatas.size()]);
|
|
|
|
String[] timearray = xLabelListData.toArray(new String[xLabelListData.size()]);
|
|
|
|
xAxis.setValueFormatter(new IndexAxisValueFormatter(timearray));
|
|
|
|
xAxis.setValueFormatter(new IndexAxisValueFormatter(timearray));
|
|
|
|
YAxis yAxis = binding.linechart.getAxisRight();
|
|
|
|
YAxis yAxis = binding.linechart.getAxisRight();
|
|
|
|
yAxis.setEnabled(false);
|
|
|
|
yAxis.setEnabled(false);
|
|
|
|
@ -347,10 +426,14 @@ public class DeviceAlarmInfoLineChartActivity extends BaseViewBindingActivity<Ac
|
|
|
|
//设置左边Y轴的样式
|
|
|
|
//设置左边Y轴的样式
|
|
|
|
YAxis axisLeft = binding.linechart.getAxisLeft();
|
|
|
|
YAxis axisLeft = binding.linechart.getAxisLeft();
|
|
|
|
axisLeft.setTextSize(12);
|
|
|
|
axisLeft.setTextSize(12);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
axisLeft.setAxisMinimum(0f);
|
|
|
|
|
|
|
|
axisLeft.setAxisMaximum((float) maxTemperature);
|
|
|
|
|
|
|
|
|
|
|
|
//设置字体颜色
|
|
|
|
//设置字体颜色
|
|
|
|
//axisLeft.setTextColor(Color.parseColor("#FC863E"));
|
|
|
|
//axisLeft.setTextColor(Color.parseColor("#FC863E"));
|
|
|
|
|
|
|
|
|
|
|
|
float ratio = (float) xlabellistdatas.size() / (float) 10;
|
|
|
|
float ratio = (float) xLabelListData.size() / (float) 10;
|
|
|
|
if (ratio < 1) {
|
|
|
|
if (ratio < 1) {
|
|
|
|
ratio = 1.0f;
|
|
|
|
ratio = 1.0f;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@ -375,4 +458,168 @@ public class DeviceAlarmInfoLineChartActivity extends BaseViewBindingActivity<Ac
|
|
|
|
// binding.linechart.moveViewToX(lastX);
|
|
|
|
// binding.linechart.moveViewToX(lastX);
|
|
|
|
// },1000);
|
|
|
|
// },1000);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void renderAddSpeed(){
|
|
|
|
|
|
|
|
xLabelListDataAddSpeed.clear();
|
|
|
|
|
|
|
|
maxAddSpeed=0;
|
|
|
|
|
|
|
|
List<Entry> entriesXAddSpeed = new ArrayList<>();
|
|
|
|
|
|
|
|
List<Entry> entriesYAddSpeed = new ArrayList<>();
|
|
|
|
|
|
|
|
List<Entry> entriesZAddSpeed = new ArrayList<>();
|
|
|
|
|
|
|
|
for (int i = 0; i < deviceAlarmDataList.size(); i++) {
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
DeviceAlarmInfoLineChartBean.DeviceVibrationMonitoringData item = deviceAlarmDataList.get(i);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
entriesXAddSpeed.add(new Entry(i, Float.parseFloat(item.getxAcceleration().toString())));
|
|
|
|
|
|
|
|
entriesYAddSpeed.add(new Entry(i, Float.parseFloat(item.getyAcceleration().toString())));
|
|
|
|
|
|
|
|
entriesZAddSpeed.add(new Entry(i, Float.parseFloat(item.getzAcceleration().toString())));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Date date = sdf.parse(item.getDeviceTime());
|
|
|
|
|
|
|
|
if(date != null){
|
|
|
|
|
|
|
|
Calendar calendar = Calendar.getInstance();
|
|
|
|
|
|
|
|
calendar.setTime(date);
|
|
|
|
|
|
|
|
xLabelListDataAddSpeed.add(sdfHourMinute.format(calendar.getTime()));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if(item.getxAcceleration()!=null&& item.getxAcceleration() >maxAddSpeed){
|
|
|
|
|
|
|
|
maxAddSpeed=item.getxAcceleration();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if(item.getyAcceleration()!=null&& item.getyAcceleration() >maxAddSpeed){
|
|
|
|
|
|
|
|
maxAddSpeed=item.getyAcceleration();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if(item.getzAcceleration()!=null&& item.getzAcceleration() >maxAddSpeed){
|
|
|
|
|
|
|
|
maxAddSpeed=item.getzAcceleration();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} catch (ParseException e) {
|
|
|
|
|
|
|
|
throw new RuntimeException(e);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
showLog(String.valueOf(deviceAlarmDataList.size()));
|
|
|
|
|
|
|
|
showLog("maxAddSpeed:"+String.valueOf(maxAddSpeed));
|
|
|
|
|
|
|
|
if(maxAddSpeed<2.5){
|
|
|
|
|
|
|
|
maxAddSpeed=2.5;
|
|
|
|
|
|
|
|
}else if(maxAddSpeed>=2.5&&maxAddSpeed<4.5){
|
|
|
|
|
|
|
|
maxAddSpeed=5;
|
|
|
|
|
|
|
|
}else if(maxAddSpeed>=4.5&&maxAddSpeed<9){
|
|
|
|
|
|
|
|
maxAddSpeed=10;
|
|
|
|
|
|
|
|
}else if(maxAddSpeed>=9&&maxAddSpeed<15){
|
|
|
|
|
|
|
|
maxAddSpeed=16;
|
|
|
|
|
|
|
|
}else if(maxAddSpeed>=15&&maxAddSpeed<30){
|
|
|
|
|
|
|
|
maxAddSpeed=31;
|
|
|
|
|
|
|
|
}else if(maxAddSpeed>=30&&maxAddSpeed<50){
|
|
|
|
|
|
|
|
maxAddSpeed=60;
|
|
|
|
|
|
|
|
}else if(maxAddSpeed>=50&&maxAddSpeed<75){
|
|
|
|
|
|
|
|
maxAddSpeed=80;
|
|
|
|
|
|
|
|
}else if(maxAddSpeed>=75&&maxAddSpeed<95){
|
|
|
|
|
|
|
|
maxAddSpeed=100;
|
|
|
|
|
|
|
|
}else if(maxAddSpeed>=95&&maxAddSpeed<125){
|
|
|
|
|
|
|
|
maxAddSpeed=130;
|
|
|
|
|
|
|
|
}else{
|
|
|
|
|
|
|
|
maxAddSpeed=maxAddSpeed+5;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
showLog("maxAddSpeed:"+String.valueOf(maxAddSpeed));
|
|
|
|
|
|
|
|
setDataAddSpeed(entriesXAddSpeed,entriesYAddSpeed,entriesZAddSpeed);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
private void setDataAddSpeed(List<Entry> entriesXAddSpeed,List<Entry> entriesYAddSpeed,List<Entry> entriesZAddSpeed) {
|
|
|
|
|
|
|
|
// 清除所有数据
|
|
|
|
|
|
|
|
binding.linechart.clear();
|
|
|
|
|
|
|
|
binding.linechart.invalidate(); // 重绘视图
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
List<ILineDataSet> sets = new ArrayList<>();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
String deviceNameLineX = deviceName+"X轴加速度";
|
|
|
|
|
|
|
|
LineDataSet dataSet1 = new LineDataSet(entriesXAddSpeed, deviceNameLineX);
|
|
|
|
|
|
|
|
dataSet1.setValueTextSize(12);
|
|
|
|
|
|
|
|
dataSet1.setValueTextColor(Color.parseColor("#ff8000"));
|
|
|
|
|
|
|
|
dataSet1.setMode(LineDataSet.Mode.CUBIC_BEZIER);
|
|
|
|
|
|
|
|
dataSet1.setLineWidth(2);
|
|
|
|
|
|
|
|
dataSet1.setCircleHoleRadius(3);
|
|
|
|
|
|
|
|
//dataSet1.enableDashedLine(5, 5, 0);
|
|
|
|
|
|
|
|
dataSet1.setCircleColor(Color.parseColor("#ff8000"));
|
|
|
|
|
|
|
|
dataSet1.setColor(Color.parseColor("#ff8000"));
|
|
|
|
|
|
|
|
dataSet1.setDrawHighlightIndicators(false);
|
|
|
|
|
|
|
|
//dataSet1.setDrawFilled(true);
|
|
|
|
|
|
|
|
//dataSet1.setFillDrawable(new GradientDrawable(GradientDrawable.Orientation.TOP_BOTTOM, new int[]{Color.argb(127, 235, 170, 106), Color.parseColor("#00FA5544")}));
|
|
|
|
|
|
|
|
dataSet1.setLineWidth(2);
|
|
|
|
|
|
|
|
dataSet1.setDrawValues(false);
|
|
|
|
|
|
|
|
sets.add(dataSet1);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
String deviceNameLineY = deviceName+"Y轴加速度";
|
|
|
|
|
|
|
|
LineDataSet dataSet2 = new LineDataSet(entriesYAddSpeed, deviceNameLineY);
|
|
|
|
|
|
|
|
dataSet2.setValueTextSize(12);
|
|
|
|
|
|
|
|
dataSet2.setValueTextColor(Color.parseColor("#0080ff"));
|
|
|
|
|
|
|
|
dataSet2.setMode(LineDataSet.Mode.CUBIC_BEZIER);
|
|
|
|
|
|
|
|
dataSet2.setLineWidth(2);
|
|
|
|
|
|
|
|
dataSet2.setCircleHoleRadius(3);
|
|
|
|
|
|
|
|
//dataSet2.enableDashedLine(5, 5, 0);
|
|
|
|
|
|
|
|
dataSet2.setCircleColor(Color.parseColor("#0080ff"));
|
|
|
|
|
|
|
|
dataSet2.setColor(Color.parseColor("#0080ff"));
|
|
|
|
|
|
|
|
dataSet2.setDrawHighlightIndicators(false);
|
|
|
|
|
|
|
|
//dataSet2.setDrawFilled(true);
|
|
|
|
|
|
|
|
//dataSet2.setFillDrawable(new GradientDrawable(GradientDrawable.Orientation.TOP_BOTTOM, new int[]{Color.argb(127, 235, 170, 106), Color.parseColor("#00FA5544")}));
|
|
|
|
|
|
|
|
dataSet2.setLineWidth(2);
|
|
|
|
|
|
|
|
dataSet2.setDrawValues(false);
|
|
|
|
|
|
|
|
sets.add(dataSet2);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
String deviceNameLineZ = deviceName+"Z轴加速度";
|
|
|
|
|
|
|
|
LineDataSet dataSet3 = new LineDataSet(entriesZAddSpeed, deviceNameLineZ);
|
|
|
|
|
|
|
|
dataSet3.setValueTextSize(12);
|
|
|
|
|
|
|
|
dataSet3.setValueTextColor(Color.parseColor("#80ff00"));
|
|
|
|
|
|
|
|
dataSet3.setMode(LineDataSet.Mode.CUBIC_BEZIER);
|
|
|
|
|
|
|
|
dataSet3.setLineWidth(2);
|
|
|
|
|
|
|
|
dataSet3.setCircleHoleRadius(3);
|
|
|
|
|
|
|
|
//dataSet3.enableDashedLine(5, 5, 0);
|
|
|
|
|
|
|
|
dataSet3.setCircleColor(Color.parseColor("#80ff00"));
|
|
|
|
|
|
|
|
dataSet3.setColor(Color.parseColor("#80ff00"));
|
|
|
|
|
|
|
|
dataSet3.setDrawHighlightIndicators(false);
|
|
|
|
|
|
|
|
//dataSet3.setDrawFilled(true);
|
|
|
|
|
|
|
|
//dataSet3.setFillDrawable(new GradientDrawable(GradientDrawable.Orientation.TOP_BOTTOM, new int[]{Color.argb(127, 235, 170, 106), Color.parseColor("#00FA5544")}));
|
|
|
|
|
|
|
|
dataSet3.setLineWidth(2);
|
|
|
|
|
|
|
|
dataSet3.setDrawValues(false);
|
|
|
|
|
|
|
|
sets.add(dataSet3);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
LineData lineData = new LineData(sets);
|
|
|
|
|
|
|
|
binding.linechart.setData(lineData);
|
|
|
|
|
|
|
|
binding.linechart.invalidate();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
XAxis xAxis = binding.linechart.getXAxis();
|
|
|
|
|
|
|
|
xAxis.setPosition(XAxis.XAxisPosition.BOTTOM);
|
|
|
|
|
|
|
|
xAxis.setAxisMinimum(1);//设置x轴最小
|
|
|
|
|
|
|
|
xAxis.setTextSize(12);
|
|
|
|
|
|
|
|
//xAxis.setTextColor(Color.parseColor("#FC863E"));
|
|
|
|
|
|
|
|
xAxis.setEnabled(true);//是否显示x轴是否禁用
|
|
|
|
|
|
|
|
xAxis.setDrawLabels(true); //设置x轴标签 即x轴上显示的数值
|
|
|
|
|
|
|
|
xAxis.setDrawGridLines(true);//是否设置x轴上每个点对应的线 即 竖向的网格线
|
|
|
|
|
|
|
|
xAxis.enableGridDashedLine(2, 2, 2); //竖线 虚线样式 lineLength控制虚线段的长度 spaceLength控制线之间的空间
|
|
|
|
|
|
|
|
xAxis.setLabelRotationAngle(40f);//设置x轴标签的旋转角度
|
|
|
|
|
|
|
|
String[] timearray = xLabelListDataAddSpeed.toArray(new String[xLabelListDataAddSpeed.size()]);
|
|
|
|
|
|
|
|
xAxis.setValueFormatter(new IndexAxisValueFormatter(timearray));
|
|
|
|
|
|
|
|
YAxis yAxis = binding.linechart.getAxisRight();
|
|
|
|
|
|
|
|
yAxis.setEnabled(false);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//设置左边Y轴的样式
|
|
|
|
|
|
|
|
YAxis axisLeft = binding.linechart.getAxisLeft();
|
|
|
|
|
|
|
|
axisLeft.setTextSize(12);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
axisLeft.setAxisMinimum(0f);
|
|
|
|
|
|
|
|
axisLeft.setAxisMaximum((float) maxAddSpeed);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//设置字体颜色
|
|
|
|
|
|
|
|
//axisLeft.setTextColor(Color.parseColor("#FC863E"));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
float ratio = (float) xLabelListDataAddSpeed.size() / (float) 10;
|
|
|
|
|
|
|
|
if (ratio < 1) {
|
|
|
|
|
|
|
|
ratio = 1.0f;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
//显示的时候是按照多大的比率缩放显示,1f表示不放大缩小
|
|
|
|
|
|
|
|
//着重说明一下下面代码的用途
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* 先将缩放比设置成0后,再去设置你想要的缩放比。
|
|
|
|
|
|
|
|
* 若不这样做的话,在当前页面重新加载数据时,你所设置的缩放比会失效,并且出现你意向不到的显示问题。
|
|
|
|
|
|
|
|
* 如果你的图表只在页面加载一次的话不需要这么做。
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
binding.linechart.zoom(0f, 1f, 0, 0);
|
|
|
|
|
|
|
|
binding.linechart.zoom(ratio, 1f, 0, 0);
|
|
|
|
|
|
|
|
//设置为不可缩放
|
|
|
|
|
|
|
|
binding.linechart.setScaleEnabled(false);
|
|
|
|
|
|
|
|
//设置为可左右滑动
|
|
|
|
|
|
|
|
binding.linechart.setDragEnabled(true);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|