androidandroid-layoutandroid-graphview

android: GraphView background doesnt draw properly


Im trying to implement a background with graphview library. Everything works fine except when the graph background is not drawn properly. Ive modified the library a little but the unmodified one also gives me the same problem. Please help

Thanks, Sahil

improper graph

My code:

@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;
}

Solution

  • The developer has fixed this problem. Referenced commit