x轴不显示当前日期(graphview)

时间:2018-12-09 19:46:28

标签: java android sql database graph

我无法获得x轴来显示当前日期。这是GraphActivity的图片。

功能如下:在MainActivity.java中,保存按钮将数据(以及当前日期)插入SQLite数据库。然后在GraphActivity.java中,将数据用于<​​strong> GraphView 。

保存完成后如何保存当前日期并显示在X轴上?

MainActivity.java

    private void insertData() {
    try {
         (...)
         Date date = new Date(new Date().getTime());    
         SimpleDateFormat sdf = new SimpleDateFormat("E yyyy.MM.dd", Locale.US);
         sdf.format(date);

        // Create a ContentValues object where column names are the keys,
        // and container attributes from the MainActivity are the values.
        ContentValues values = new ContentValues();
        values.put(DexameniEntry.COLUMN_CONTAINER_NAME, "TODO");
        values.put(DexameniEntry.COLUMN_a, X1aInput);
        values.put(DexameniEntry.COLUMN_DATE, String.valueOf(date));
        values.put(DexameniEntry.COLUMN_b, X1bInput);
        values.put(DexameniEntry.COLUMN_c, X1cInput);
        values.put(DexameniEntry.COLUMN_d, dX1StringDouble);
        values.put(DexameniEntry.COLUMN_e, eX1StringDouble);
        values.put(DexameniEntry.COLUMN_percent, percentX1fromDoubletoString);

GraphActivity

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;
import java.util.*;


public class GraphActivity extends AppCompatActivity {

public GraphView bigGraphX1;

SQLiteDatabase sqLiteDatabase;
ResultsDbHelper mDbHelper;

public LineGraphSeries<DataPoint> series = new LineGraphSeries<>(new DataPoint[0]);


@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.graph_activity);

    bigGraphX1 = findViewById(R.id.bigGraph);
    mDbHelper = new ResultsDbHelper(this);
    sqLiteDatabase = mDbHelper.getWritableDatabase();

    final SimpleDateFormat sdf = new SimpleDateFormat("E yyyy.MM.dd", Locale.US);

    bigGraphX1.getGridLabelRenderer().setLabelFormatter(new DefaultLabelFormatter() {
        @Override
        public String formatLabel(double value, boolean isValueX) {
            if (isValueX) {
                return sdf.format(new Date((long) value));
            }
            return super.formatLabel(value, isValueX);

        }
    });

    bigGraphX1.addSeries(series);
    series.resetData(getDataPoint());

0 个答案:

没有答案