私は、アプリケーションのMPAndroidチャートを使って、X軸の "weight"値とX軸の "date"値を使ってsqliteデータベースからグラフを描画しています。Android MPAndroidCharts LineChart値をスキップ
問題は、データベースの一部の行にその重み値があることです。すべての行にウェイトレイアウトがあると、マイコードはチャームのように機能しますが、ウェイト値を持たない行があり、次のウェイト値にはウェイト値が含まれていると、チャートのYAxesにスペースが残っています日付の値はXAxesに設定されます。その結果、ウェイト行の後に来る値が1ポイント先に移動するため、ウェイト値のないすべての行についてY軸上の値が失われます。たとえば:
私はチャートを設定するため、このコードがあります。
public void setUpCharts(){
chart = (LineChart) rootView.findViewById(R.id.weightChart);
chart.setNoDataTextDescription("Nothing");
chart.setDrawBorders(false);
chart.setDescription("");
chart.getXAxis().setPosition(XAxis.XAxisPosition.BOTTOM);
chart.getAxisRight().setEnabled(false);
chart.getAxisLeft().setEnabled(false);
chart.getAxisLeft().setDrawGridLines(false);
chart.getAxisRight().setDrawGridLines(false);
chart.getXAxis().setDrawGridLines(false);
chart.getXAxis().setDrawAxisLine(false);
chart.getLegend().setEnabled(false);
chart.setScaleEnabled(false);
chart.setPinchZoom(false);
chart.setDoubleTapToZoomEnabled(false);
weights = new ArrayList<>(); //Pesos
dates = new ArrayList<String>(); //Días del mes
getChartData();
LineDataSet dataSet = new LineDataSet(weights, "Weights");
dataSet.setDrawCubic(false);
dataSet.setCircleRadius(4);
dataSet.setLineWidth(3);
dataSet.setDrawValues(true);
dataSet.setColor(getContext().getResources().getColor(R.color.colorWeightChart));
dataSet.setCircleColor(getContext().getResources().getColor(R.color.colorWeightChart));
dataSet.setCircleColorHole(getContext().getResources().getColor(R.color.colorWeightChart));
LineData data = new LineData(dates, dataSet);
chart.setData(data);
//LimitLine
String weight_get = PreferenceManager.getDefaultSharedPreferences(getContext()).getString("Goal_weight", null);
if(!weight_get.equals(null) && !weight_get.equals("")){
float weight_goal = Float.valueOf(weight_get);
YAxis leftAxis = chart.getAxisLeft();
LimitLine ll = new LimitLine(weight_goal);
ll.setLineColor(getContext().getResources().getColor(R.color.weightTabFAB));
ll.setLineWidth(1f);
ll.enableDashedLine(10f, 10f, 0f);
leftAxis.addLimitLine(ll);
float YMax= dataSet.getYMax();
if(weight_goal > YMax){
float difference = weight_goal - YMax;
chart.getAxisRight().setAxisMaxValue(weight_goal + difference); //So the limit line will be always visible
chart.getAxisLeft().setAxisMaxValue(weight_goal + difference);
}
}
chart.setVisibleXRangeMaximum(5f);
}
をそして私は私のSQLiteデータベースから値を取得するすべてのグラフのデータを設定するためにgetChartDataを使用しています。それは重みが存在する行の値だけを追加することになっていて、実際にログは正しく動作することを示しているので、どうすれば修正できるのか分かりません。
protected void getChartData(){
IDs = new ArrayList<Integer>();
Cursor data = dataSource.getAllItems();
if(data!=null) {
while(data.moveToNext()){
int id = data.getInt(data.getColumnIndex(RecordsDataSource.ColumnRecords.ID_RECORDS));
String weight= data.getString(data.getColumnIndex(RecordsDataSource.ColumnRecords.WEIGHTS_RECORDS));
if(weight!=null && !weight.equals("")){
long milisDate =data.getLong(data.getColumnIndex(RecordsDataSource.ColumnRecords.DATES_RECORDS));
String date = Utils.milisToDate(milisDate, "dd/MM");
IDs.add(id);
weights.add(new Entry(Float.valueOf(weight), id -1));
dates.add(date);
Log.i("ID "+ String.valueOf(id),"Not null, "+ weight);
}else{
Log.i("ID "+ String.valueOf(id), "Null");
}
}
data.close();
}
}
私はいつもこの問題を解決しようとしていますが、何も機能していません。 誰かが私を助けてくれますか?ところで、私の悪い英語を申し訳ありません。
ありがとうございます!これは私の問題を解決しました。 それは愚かなerorだったが、私はそれに気付かなかった – Javierd98