Android GraphView 库 - 使用 GraphView.getSecondScale().addSeries(series) 添加的系列无法删除
Android GraphView library - Series added with GraphView.getSecondScale().addSeries(series) cannot be removed
我的图表中有三个系列。系列 1 和系列 2 使用左侧刻度,系列 3 通过添加 with
使用第二个刻度
CurrentPlot.getSecondScale().addSeries(sensor3Series);
用户可以选择查看所有三个系列或仅查看其中的一部分。
可以使用
删除系列 1 和系列 2
currentPlot.removeSeries(sensor1Series);
currentPlot.removeSeries(sensor2Series);
但系列 3 无法删除。
我试过了
currentPlot.removeAllSeries();
currentPlot.removeSeries(sensor3Series);
两者都不删除使用第二个尺度的系列。
请指教如何删除
代码摘录:
初始化(简化):
private void initChart(boolean isContinuous) {
// find the temperature levels plot in the layout
currentPlot = (GraphView) findViewById(R.id.graph);
// setup and format sensor 1 data series
sensor1Series = new LineGraphSeries<>();
// setup and format sensor 2 data series
sensor2Series = new LineGraphSeries<>();
// setup and format sensor 3 data series
sensor3Series = new LineGraphSeries<>();
currentPlot.getGridLabelRenderer().setNumVerticalLabels(10);
currentPlot.getGridLabelRenderer().setNumHorizontalLabels(5);
sensor1Series.setColor(Color.YELLOW);
sensor2Series.setColor(Color.RED);
sensor3Series.setColor(Color.GREEN);
currentPlot.getGridLabelRenderer().setVerticalAxisTitle("Watt");
// SKIPPED code to add data to the 3 series with appendData()
currentPlot.setTitle(dayToShow);
minMaxVal = getMinMax();
// SKIPPED set min and max bounds of both scales to manual and set the values
// SKIPPED add setOnDataPointTapListeners to all three series with setOnDataPointTapListener()
currentPlot.addSeries(sensor2Series);
currentPlot.getSecondScale().addSeries(sensor3Series);
currentPlot.addSeries(sensor1Series);
}
在 onClick 中删除所选系列(通过 CheckBox)的代码:
case R.id.cb_solar:
CheckBox cbSolar = (CheckBox)findViewById(R.id.cb_solar);
if (cbSolar.isChecked()) {
currentPlot.addSeries(sensor1Series);
showSeries1 = true;
} else {
currentPlot.removeSeries(sensor1Series);
showSeries1 = false;
}
break;
case R.id.cb_cons:
CheckBox cbCons = (CheckBox)findViewById(R.id.cb_cons);
if (cbCons.isChecked()) {
currentPlot.addSeries(sensor2Series);
showSeries2 = true;
} else {
currentPlot.removeSeries(sensor2Series);
showSeries2 = false;
}
break;
case R.id.cb_light:
CheckBox cbLight = (CheckBox)findViewById(R.id.cb_light);
if (cbLight.isChecked()) {
currentPlot.getSecondScale().addSeries(sensor3Series);
showSeries3 = true;
} else {
currentPlot.removeAllSeries();
//removeSeries(sensor3Series);
showSeries3 = false;
}
break;
编辑:
解决问题 - 将系列的颜色设置为 Color.TRANSPARENT
case R.id.cb_light:
CheckBox cbLight = (CheckBox)findViewById(R.id.cb_light);
if (cbLight.isChecked()) {
currentPlot.getSecondScale().addSeries(sensor3Series);
sensor3Series.setColor(Color.GREEN);
showSeries3 = true;
} else {
currentPlot.removeSeries(sensor3Series);
sensor3Series.setColor(Color.TRANSPARENT);
showSeries3 = false;
}
break;
这使得第三个系列不可见,但右侧的第二个刻度仍然可见。
尝试:
graph.getSecondScale().getSeries().clear();
我的图表中有三个系列。系列 1 和系列 2 使用左侧刻度,系列 3 通过添加 with
使用第二个刻度CurrentPlot.getSecondScale().addSeries(sensor3Series);
用户可以选择查看所有三个系列或仅查看其中的一部分。
可以使用
删除系列 1 和系列 2currentPlot.removeSeries(sensor1Series);
currentPlot.removeSeries(sensor2Series);
但系列 3 无法删除。 我试过了
currentPlot.removeAllSeries();
currentPlot.removeSeries(sensor3Series);
两者都不删除使用第二个尺度的系列。
请指教如何删除
代码摘录:
初始化(简化):
private void initChart(boolean isContinuous) {
// find the temperature levels plot in the layout
currentPlot = (GraphView) findViewById(R.id.graph);
// setup and format sensor 1 data series
sensor1Series = new LineGraphSeries<>();
// setup and format sensor 2 data series
sensor2Series = new LineGraphSeries<>();
// setup and format sensor 3 data series
sensor3Series = new LineGraphSeries<>();
currentPlot.getGridLabelRenderer().setNumVerticalLabels(10);
currentPlot.getGridLabelRenderer().setNumHorizontalLabels(5);
sensor1Series.setColor(Color.YELLOW);
sensor2Series.setColor(Color.RED);
sensor3Series.setColor(Color.GREEN);
currentPlot.getGridLabelRenderer().setVerticalAxisTitle("Watt");
// SKIPPED code to add data to the 3 series with appendData()
currentPlot.setTitle(dayToShow);
minMaxVal = getMinMax();
// SKIPPED set min and max bounds of both scales to manual and set the values
// SKIPPED add setOnDataPointTapListeners to all three series with setOnDataPointTapListener()
currentPlot.addSeries(sensor2Series);
currentPlot.getSecondScale().addSeries(sensor3Series);
currentPlot.addSeries(sensor1Series);
}
在 onClick 中删除所选系列(通过 CheckBox)的代码:
case R.id.cb_solar:
CheckBox cbSolar = (CheckBox)findViewById(R.id.cb_solar);
if (cbSolar.isChecked()) {
currentPlot.addSeries(sensor1Series);
showSeries1 = true;
} else {
currentPlot.removeSeries(sensor1Series);
showSeries1 = false;
}
break;
case R.id.cb_cons:
CheckBox cbCons = (CheckBox)findViewById(R.id.cb_cons);
if (cbCons.isChecked()) {
currentPlot.addSeries(sensor2Series);
showSeries2 = true;
} else {
currentPlot.removeSeries(sensor2Series);
showSeries2 = false;
}
break;
case R.id.cb_light:
CheckBox cbLight = (CheckBox)findViewById(R.id.cb_light);
if (cbLight.isChecked()) {
currentPlot.getSecondScale().addSeries(sensor3Series);
showSeries3 = true;
} else {
currentPlot.removeAllSeries();
//removeSeries(sensor3Series);
showSeries3 = false;
}
break;
编辑: 解决问题 - 将系列的颜色设置为 Color.TRANSPARENT
case R.id.cb_light:
CheckBox cbLight = (CheckBox)findViewById(R.id.cb_light);
if (cbLight.isChecked()) {
currentPlot.getSecondScale().addSeries(sensor3Series);
sensor3Series.setColor(Color.GREEN);
showSeries3 = true;
} else {
currentPlot.removeSeries(sensor3Series);
sensor3Series.setColor(Color.TRANSPARENT);
showSeries3 = false;
}
break;
这使得第三个系列不可见,但右侧的第二个刻度仍然可见。
尝试:
graph.getSecondScale().getSeries().clear();