Graphview - Customizing the X axis

0

I'm using Graphview 4.2.1 to plot a chart. Instead of using numbers on the X axis, I need to set the measurement time. I can pick up the time and put it on the axis, but when I add a new point, it renames all points on the X axis to the new time, instead of just changing the new point. Example: p1 (21:08, 50), p2 (21: 15,45), p3 (21: 20,48) .... if we plot these points, all the X axis is 21:20. Follow the code below.

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_tela_principal);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    g = findViewById(R.id.graphTela);
    g.setVisibility(View.INVISIBLE);
    g.getViewport().setXAxisBoundsManual(true);
    g.getViewport().setMinX(0);
    g.getViewport().setMaxX(4);

    // permite setar os limites do gráfico
    g.getViewport().setYAxisBoundsManual(true);
    g.getViewport().setMinY(-80);
    g.getViewport().setMaxY(-60);

    g.setBackgroundColor(Color.rgb(255,255,255));
    g.getViewport().setScrollable(true);// pode ir e voltar no grafico

    Calendar calendar = Calendar.getInstance();
    final SimpleDateFormat formato = new SimpleDateFormat("kk:mm");
    g.getGridLabelRenderer().setLabelFormatter(new DefaultLabelFormatter() {
        @Override
        public String formatLabel(double value, boolean isValueX) {
            if (isValueX) {
                // show normal x values
                return formato.format(new Date().getTime()); // padrao
            } else {
                // show currency for y values
                return super.formatLabel(value, isValueX);
            }
        }
    });



@Override
public void onResume() {
    super.onResume();
    mTimer1 = new Runnable() {
        @Override
        public void run() {

            temp = buscarDados();
            x1++;

            ponto = new DataPoint(x1, temp);
            g.appendData(ponto, true, 20);

            mHandler01.postDelayed(this, tempoDeColeta);
        }

    };
    mHandler01.postDelayed(mTimer1, tempoDeColeta);

}
    
asked by anonymous 23.08.2018 / 03:18

0 answers