1.1
import com.github.mikephil.charting.charts.CombinedChart;
import com.github.mikephil.charting.data.BarData;
import com.github.mikephil.charting.data.BarDataSet;
import com.github.mikephil.charting.data.BarEntry;
import com.github.mikephil.charting.data.CandleData;
import com.github.mikephil.charting.data.CandleDataSet;
import com.github.mikephil.charting.data.CandleEntry;
import com.github.mikephil.charting.data.Entry;
import com.github.mikephil.charting.data.LineData;
import com.github.mikephil.charting.data.LineDataSet;
/**
* Created by wblobin on 2016/8/29.
* qq:563084073
*/
public class CalculateChartUDP {
public static boolean addLine(CombinedChart kline_chart, float entryVals[]) {
boolean isAddSuccess = false;
LineData lineData = kline_chart.getLineData();
boolean isAdd[] = new boolean[3];
if (lineData != null) {
int dataSetCount = lineData.getDataSetCount();
for (int i = 0; i < dataSetCount; i++) {
LineDataSet lineDataSet = (LineDataSet) lineData.getDataSetByIndex(i);
if (lineDataSet != null) {
int count = lineDataSet.getEntryCount();
//Entry entry = new Entry(getSum(CMAs[i], kLineDatas.size() - 1), count);
Entry entry = new Entry(entryVals[i], count);
isAdd[i] = lineDataSet.addEntry(entry);
if (isAdd[i]) {
isAddSuccess = true;
lineDataSet.notifyDataSetChanged();
} else {
return false;
}
}
}
}
return isAddSuccess;
}
public static boolean addCandle(CombinedChart kline_chart, float open, float close, float high, float low ) {
boolean isAddSuccess = false;
CandleData candleData = kline_chart.getCandleData();
if (candleData != null) {
int indexLastDataSet = candleData.getDataSetCount() - 1;
CandleDataSet candleDataSet = (CandleDataSet) candleData.getDataSetByIndex(indexLastDataSet);
if (candleDataSet != null) {
int count = candleDataSet.getEntryCount();
CandleEntry candleEntry = new CandleEntry(count, high, low, open, close);
isAddSuccess = candleDataSet.addEntry(candleEntry);
if (isAddSuccess) {
candleDataSet.notifyDataSetChanged();
}
}
}
return isAddSuccess;
}
public static boolean addBar(CombinedChart kline_chart, float barEntryVal) {
boolean isAddSuccess = false;
BarData barData = kline_chart.getBarData();
if (barData != null) {
int indexLastDataSet = barData.getDataSetCount() - 1;
BarDataSet barDataSet = (BarDataSet) barData.getDataSetByIndex(indexLastDataSet);
if (barDataSet != null) {
int count = barDataSet.getEntryCount();
BarEntry barEntry = new BarEntry(barEntryVal, count);
isAddSuccess = barDataSet.addEntry(barEntry);
if (isAddSuccess) {
barDataSet.notifyDataSetChanged();
}
}
}
return isAddSuccess;
}
public static boolean removeLine(CombinedChart kline_chart) {
boolean isRemoveSuccess = false;
boolean isRemove[] = new boolean[3];
LineData lineData = kline_chart.getLineData();
if (lineData != null) {
int dataSetCount = lineData.getDataSetCount();
for (int i = 0; i < dataSetCount; i++) {
LineDataSet lineDataSet = (LineDataSet) lineData.getDataSetByIndex(i);
if (lineDataSet != null) {
int count = lineDataSet.getEntryCount();
isRemove[i] = lineData.removeEntry(lineDataSet.getEntryForXIndex(count - 1), i);
}
}
if (isRemove[0] && isRemove[1] && isRemove[2]) {
isRemoveSuccess = true;
lineData.notifyDataChanged();
}
}
return isRemoveSuccess;
}
public static boolean removeCanadle(CombinedChart kline_chart) {
boolean isRemoveSuccess = false;
CandleData candleData = kline_chart.getCandleData();
if (candleData != null) {
int indexLastDataSet = candleData.getDataSetCount() - 1;
CandleDataSet candleDataSet = (CandleDataSet) candleData.getDataSetByIndex(indexLastDataSet);
if (candleDataSet != null) {
int count = candleDataSet.getEntryCount();
isRemoveSuccess = candleData.removeEntry(candleDataSet.getEntryForXIndex(count - 1), indexLastDataSet);
if (isRemoveSuccess) {
candleData.notifyDataChanged();
}
}
}
return isRemoveSuccess;
}
public static boolean removeBar(CombinedChart kline_chart) {
boolean isRemoveSuccess = false;
BarData barData = kline_chart.getBarData();
if (barData != null) {
int indexLastDataSet = barData.getDataSetCount() - 1;
BarDataSet barDataSet = (BarDataSet) barData.getDataSetByIndex(indexLastDataSet);
if (barDataSet != null) {
int count = barDataSet.getEntryCount();
isRemoveSuccess = barData.removeEntry(barDataSet.getEntryForXIndex(count - 1), indexLastDataSet);
if (isRemoveSuccess) {
barData.notifyDataChanged();
}
}
}
return isRemoveSuccess;
}
}
网友评论