简体   繁体   English

更改比例后重绘GraphView

[英]Redraw GraphView after scale change

I'm working on an app that uses GraphView. 我正在使用GraphView的应用程序。 Users can scale the graph (zoom in, zoom out), and they can use a 'reset zoom' button to reset to the default view they get when they open the graph. 用户可以缩放图形(放大,缩小),并且可以使用“重置缩放”按钮将其重置为打开图形时获得的默认视图。 I got it working, but the graph doesn't update when I press the button. 我可以使用它,但是按下按钮时图形不会更新。 Only if I press the button THEN scroll the graph will it reset to the default zoom. 仅当我按下按钮然后滚动图形时,它才会重置为默认缩放比例。 I was looking for redraw() or refresh() methods to fix it, but nothing's worked so far. 我一直在寻找redraw()或refresh()方法来修复它,但到目前为止没有任何效果。 Here's my code: 这是我的代码:

 resett.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            //set manual X bounds
            graph.getViewport().setXAxisBoundsManual(true);
            graph.getViewport().setMinX(-10);
            graph.getViewport().setMaxX(10);

            // set manual Y bounds
            graph.getViewport().setYAxisBoundsManual(true);
            graph.getViewport().setMinY(-15);
            graph.getViewport().setMaxY(15);

            graph.refreshDrawableState();
        }
    });

Any leads? 有线索吗?

For changes to take effect, you need to call this instead of refreshDrawableState: 为了使更改生效,您需要调用此函数而不是refreshDrawableState:

    graph.onDataChanged(false, false);

You may modify the parameters to see the change in the graph that you are looking for. 您可以修改参数以查看所需图形中的更改。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM