0
我有一個小問題,實時組合圖由MPAndroidChart。我有兩個不同的圖表,它在兩個單獨的圖表中工作,但我想合併爲一個。主要的問題是,當傳入值時圖中沒有任何內容。我明白了,參考文件沒問題。組合圖實時圖
這裏是我的代碼:
private void IntialcombinedChart(){
mChart = (CombinedChart) findViewById(R.id.chartFetalandToco);
mChart.setDescription("");
mChart.setNoDataText("No data yet");
mChart.setDrawGridBackground(false);
mChart.setTouchEnabled(true);
mChart.setDragEnabled(true);
mChart.setScaleEnabled(true);
mChart.setDrawGridBackground(false);
mChart.setVisibleXRangeMaximum((float)10);
XAxis x1 = mChart.getXAxis();
x1.setDrawGridLines(false);
x1.setAxisMaxValue(1200);
x1.setAvoidFirstLastClipping(true);
YAxis y1 = mChart.getAxisLeft();
y1.setAxisMaxValue(255);
y1.setAxisMinValue(0);
y1.setDrawGridLines(true);
YAxis y12 = mChart.getAxisRight();
y12.setEnabled(false);
cData = new CombinedData();
cData.setData(new LineData());
cData.setData(new ScatterData());
mChart.setData(cData);
mChart.invalidate();
}
public ScatterDataSet createFetalSet(){
ScatterDataSet set = new ScatterDataSet(null,"Fetal");
set.setScatterShapeSize(7.5f);
set.setDrawValues(false);
set.setValueTextSize(10f);
set.setDrawValues(false);
set.setColor(ColorTemplate.COLORFUL_COLORS[2]);
set.setAxisDependency(YAxis.AxisDependency.LEFT);
return set;
}
private LineDataSet createTocoSet(){
LineDataSet set = new LineDataSet(null,"Toco");
set.setDrawCircles(false);
set.setDrawCubic(true);
set.setDrawValues(false);
set.setColor(ColorTemplate.COLORFUL_COLORS[3]);
set.setAxisDependency(YAxis.AxisDependency.LEFT);
return set;
}
public void AddFetalEntry(float sinValue){
CombinedData data = mChart.getData();
if (data != null) {
LineDataSet dataSetGraphA = (LineDataSet) data.getDataSetByIndex(0);
ScatterDataSet dataSetGraphB = (ScatterDataSet) data.getDataSetByIndex(1);
if (dataSetGraphA == null) {
dataSetGraphA = createTocoSet();
data.addDataSet(dataSetGraphA);
}
if (dataSetGraphB == null) {
dataSetGraphB = createFetalSet();
data.addDataSet(dataSetGraphB);
}
data.addXValue("");
data.addEntry(new Entry(sinValue, dataSetGraphA.getEntryCount()), 0);
data.addEntry(new Entry(sinValue, dataSetGraphB.getEntryCount()), 1);
data.notifyDataChanged();
// let the chart know it's data has changed
mChart.notifyDataSetChanged();
mChart.invalidate(); // refresh
mChart.setVisibleXRangeMaximum(2000);
//int valueCount = data.getXValCount();
mChart.moveViewToX(data.getXValCount() - 2000);
}
}
我覺得我寫了一個良好的代碼,但它不工作。我嘗試了很多方法來解決這個問題,但我不能。當圖表上出現相同的值時,我會很高興。
我希望有人可以幫助我。