gpt4 book ai didi

java - 图表引擎 : remove chart before and redraw new chart

转载 作者:太空狗 更新时间:2023-10-29 16:41:00 24 4
gpt4 key购买 nike

我真的很沮丧使用 achartengine 库重绘图表,我已经删除了 View ,但我的图表只是在顶部图表上新建,我真的很困惑......我已经搜索了任何方法但我无法得到它......这是我之前的问题:achartengine : how to repaint / redraw chart

如何在每次滑动搜索栏时重新绘制图表?

这是我的源代码:

        @Override
protected void onResume() {
// TODO Auto-generated method stub
super.onResume();

if (mChartView == null) {
lnChart = (LinearLayout) findViewById(R.id.chart);
mChartView = ChartFactory.getLineChartView(this, mDataset, mRenderer);
mChartView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
SeriesSelection seriesSelection = mChartView.getCurrentSeriesAndPoint();
double[] xy = mChartView.toRealPoint(0);
if (seriesSelection == null) {
Toast.makeText(getApplicationContext(), "tidak ada chart yang dipilih", Toast.LENGTH_SHORT)
.show();
} else {
Toast.makeText(
getApplicationContext(),
"Nilai " + listData.get(seriesSelection.getPointIndex()).getInuNilai()+
" tanggal " + listData.get(seriesSelection.getPointIndex()).getTanggal(),
Toast.LENGTH_SHORT).show();
}
}
});
lnChart.addView(mChartView, 0, new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));

}
else {
mChartView.repaint();

}
}

public void renderChart(ArrayList<NabDetail> listData) {
// TODO Auto-generated method stub

String seriesTitle = "";
XYSeries series = new XYSeries(seriesTitle);
mDataset.addSeries(series);
mCurrentSeries = series;
XYSeriesRenderer renderer = new XYSeriesRenderer();
renderer.setFillBelowLine(true);
renderer.setFillBelowLineColor(Color.TRANSPARENT);
renderer.setColor(Color.YELLOW);
mRenderer.addSeriesRenderer(renderer);
mRenderer.setInScroll(true);
mRenderer.setShowLegend(false);
//hide x label
mRenderer.setXLabels(RESULT_OK);
renderer.setFillPoints(true);
mCurrentRenderer = renderer;


for (int i = 0; i < listData.size(); i++) {

mCurrentSeries.add(i,listData.get(i).getInuNilai()
);

}

if (mChartView != null) {

lnChart.removeViewAt(0);
mChartView.repaint();
}
}
}

我用过 lnChart.removeViewAt(0);
mChartView.repaint();
但我的图表仍然没有重绘...那么之前如何重绘和删除图表?我必须在哪里放置正确的代码?

拜托..我希望有人能帮我解决这个问题

最佳答案

这段代码应该适合您。

public void renderChart(ArrayList<NabDetail> listData) {
// Clear your previous chart DataSet and Renderer.
mDataSet.clear();
mRenderer = new XYMultipleSeriesRenderer();

String seriesTitle = "";
XYSeries series = new XYSeries(seriesTitle);
mDataset.addSeries(series);
mCurrentSeries = series;
XYSeriesRenderer renderer = new XYSeriesRenderer();
renderer.setFillBelowLine(true);
renderer.setFillBelowLineColor(Color.TRANSPARENT);
renderer.setColor(Color.YELLOW);
mRenderer.addSeriesRenderer(renderer);
mRenderer.setInScroll(true);
mRenderer.setShowLegend(false);
//hide x label
mRenderer.setXLabels(RESULT_OK);
renderer.setFillPoints(true);
mCurrentRenderer = renderer;

for (int i = 0; i < listData.size(); i++) {
mCurrentSeries.add(i,listData.get(i).getInuNilai());
}

// repaint your chart with new mDataSet and mRenderer.
repaint();
}

private void repaint() {
lnChart = (LinearLayout) findViewById(R.id.chart);

if (mChartView != null) {
lnChart.removeView(mChartView);
}

mChartView = ChartFactory.getLineChartView(this, mDataset, mRenderer);

lnChart.addView(mChartView, 0, new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
}

关于java - 图表引擎 : remove chart before and redraw new chart,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17780085/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com