我正在尝试使用 graphview 库实现背景。一切正常,除非图形背景未正确绘制。我已经对库进行了一些修改,但未修改的库也给了我同样的问题。请帮忙
谢谢, 萨希尔
我的代码:
@Override
public View onCreateView(final LayoutInflater inflater, final ViewGroup container, final Bundle savedInstanceState) {
final View inflatedView = inflater.inflate(R.layout.fragment_graph, container, false);
this.graphView = new LineGraphView(this.getActivity().getApplicationContext(), "") {
@Override
protected String formatLabel(final double value, final boolean isValueX) {
if (isValueX) {
final SimpleDateFormat dateFormat = new SimpleDateFormat("HH:mm");
return dateFormat.format(new Date((long) value * 1000));
} else {
return super.formatLabel(value, isValueX); // let the y-value be normal-formatted
}
}
};
this.graphView.setVerticalLabels(new String[]{"100", "90", "80", "70", "60", "50", "40", "30", "20", "10", "0"});
this.graphView.setScrollable(true);
this.graphView.setScalable(true);
this.graphView.setDrawBackground(true);
this.graphView.setBackgroundColor(Color.rgb(194, 223, 255));
this.graphView.setManualYAxis(true);
this.graphView.setManualYAxisBounds(100.0, 0.0);
this.graphView.setEnabled(false);
this.updateGraph();
final LinearLayout layout = (LinearLayout) inflatedView.findViewById(R.id.layout_graph_view);
layout.addView(this.graphView);
return inflatedView;
}
private void updateGraph() {
// Removed a lot of code to get the graph data
final Long currentTime = System.currentTimeMillis() / 1000L;
if (this.seriesSet) {
//TODO: this.graphView.removeSeries( 0 );
}
this.graphView.addSeries(dataSet.first);
if ((dataSet.second + 86400L) < currentTime) {
this.graphView.setViewPort((currentTime - 43200), 43200);
}
this.seriesSet = true;
}