GraphView is not updated when new data is added

前端 未结 3 1530
傲寒
傲寒 2021-01-16 23:18

I have a GraphView that is not updated when new data is added, it changes the Y value to accommodate for the new data, but it doesn\'t draw them, here is the co

3条回答
  •  广开言路
    2021-01-17 00:00

    For changes to take effect, you need to call:

    graphView.onDataChanged(false, false);
    

    instead of graphView.redrawAll() in the View.OnClickListener implementation. You must play with the parameters to ensure the best performance, take a look at the javadoc in the source code:

    /**
     * Call this to let the graph redraw and recalculate the viewport.
     *
     * This will be called when a new series was added or removed and when data was appended 
     * via {@link com.jjoe64.graphview.series.BaseSeries#appendData(com.jjoe64.graphview.series.DataPointInterface, boolean, int)}
     * or {@link com.jjoe64.graphview.series.BaseSeries#resetData(com.jjoe64.graphview.series.DataPointInterface[])}.
     *
     * @param keepLabelsSize true if you don't want to recalculate the size of the labels. 
     *                       It is recommended to use "true" because this will improve 
     *                       performance and prevent a flickering.
     * @param keepViewport true if you don't want that the viewport will be recalculated.
     *                     It is recommended to use "true" for performance.
     */
    public void onDataChanged(boolean keepLabelsSize, boolean keepViewport) { /*...*/ }
    

    No need for Thread/Runnable at all.

提交回复
热议问题