Линейная диаграмма Android с использованием MPChart Линии Android смешиваются и не показывают true в соответствии со значением

#android #mpandroidchart #linechart

#Android #mpandroidchart #линейная диаграмма

Вопрос:

Я разработал линейную диаграмму с использованием MpChartAndroid. Есть 3 строки. Но моя первая строка содержит гораздо больше значений, чем другие строки. Но график не показывает строки на самом деле.

введите описание изображения здесь

Вы можете видеть, что первая строка имеет значение 20 920 000, вторая 215 378, третья 11 300. Но этот график не соответствует действительности. На графике высота первой и второй строк почти одинакова.Как сделать этот график красивым.Есть идея показать линии намного надежнее

 yVals1 = new ArrayList<>();
yVals2 = new ArrayList<>();
yVals3 = new ArrayList<>();

for (int i = 0; i < amountByDateList.size(); i  ) {
    yVals1.add(new Entry(i, amountByDateList.get(i).getPurchases()));
}

for (int i = 0; i < amountByDateList.size(); i  ) {
    yVals2.add(new Entry(i, amountByDateList.get(i).getBonuses()));
}

for (int i = 0; i < amountByDateList.size(); i  ) {
    yVals3.add(new Entry(i, amountByDateList.get(i).getWriteOff()));
}

List<String> xValList = new LinkedList<>();
for (int i = 0; i < amountByDateList.size(); i  ) {
    xValList.add(amountByDateList.get(i).getChequeDate());
}


mLineChart.setOnChartValueSelectedListener(this);
mLineChart.setTouchEnabled(true);
mLineChart.setDragDecelerationFrictionCoef(0.9f);
mLineChart.setDragEnabled(true);
mLineChart.getDescription().setEnabled(false);
mLineChart.setScaleEnabled(true);
mLineChart.setDrawGridBackground(false);
mLineChart.setHighlightPerDragEnabled(false);
mLineChart.setPinchZoom(true);
mLineChart.setAutoScaleMinMaxEnabled(true);
mLineChart.setBackgroundColor(getResources().getColor(R.color.white));
mLineChart.animateY(1000);
mLineChart.setVisibleXRangeMinimum(1);
mLineChart.setLayerType(View.LAYER_TYPE_NONE, null);
mLineChart.getRenderer().getPaintRender().setShadowLayer(10, 0, 20, getColorWithAlpha(Color.GRAY, 0.1f));
mLineChart.notifyDataSetChanged();
mLineChart.invalidate();

XAxis xAxis = mLineChart.getXAxis();
xAxis.setTextSize(11f);
xAxis.setTextColor(getResources().getColor(R.color.line_chart_color));
xAxis.setDrawGridLines(false);
xAxis.setDrawAxisLine(false);
xAxis.setGranularity(1);
xAxis.setPosition(XAxis.XAxisPosition.BOTTOM);
xAxis.setValueFormatter(new ClaimsXAxisValueFormatter(xValList));
xAxis.setLabelRotationAngle(-70);

YAxis leftAxis = mLineChart.getAxisLeft();
leftAxis.setTextColor(ColorTemplate.getHoloBlue());
leftAxis.setAxisMinimum(0f);
leftAxis.setDrawGridLines(false);
leftAxis.setGranularityEnabled(true);
leftAxis.setEnabled(false);

YAxis rightAxis = mLineChart.getAxisRight();
rightAxis.setTextColor(Color.RED);
rightAxis.setAxisMinimum(0);
rightAxis.setDrawGridLines(false);
rightAxis.setEnabled(false);
rightAxis.setDrawZeroLine(false);
rightAxis.setGranularityEnabled(false);

mLineChart.getLegend().setEnabled(false);


LineDataSet set1, set2, set3;


set1 = new LineDataSet(yVals1, "");
set1.setAxisDependency(YAxis.AxisDependency.LEFT);
set1.setColor(getResources().getColor(R.color.shopping_amount_color));
set1.setCircleColor(getResources().getColor(R.color.shopping_amount_color));
set1.setLineWidth(4f);
set1.setCircleRadius(1f);
set1.setFillAlpha(60);
set1.setFillColor(getResources().getColor(R.color.shopping_amount_color));
set1.setHighLightColor(getResources().getColor(R.color.shopping_amount_color));
set1.setDrawCircleHole(false);


set2 = new LineDataSet(yVals2, "");
set2.setAxisDependency(YAxis.AxisDependency.RIGHT);
set2.setColor(getResources().getColor(R.color.filled_up_rewards_color));
set2.setLineWidth(4f);
set2.setCircleRadius(1f);
set2.setFillAlpha(60);
set2.setFillColor(getResources().getColor(R.color.filled_up_rewards_color));
set2.setDrawCircleHole(false);
set2.setCircleColor(getColorWithAlpha(getResources().getColor(R.color.filled_up_rewards_color), 0.4f));
set2.setHighLightColor(getResources().getColor(R.color.filled_up_rewards_color));


set3 = new LineDataSet(yVals3, "");
set3.setAxisDependency(YAxis.AxisDependency.RIGHT);
set3.setColor(getResources().getColor(R.color.write_off_rewards_color));
set3.setLineWidth(4f);
set3.setCircleRadius(1f);
set3.setFillAlpha(60);
set3.setFillColor(getResources().getColor(R.color.write_off_rewards_color));
set3.setDrawCircleHole(false);
set3.setCircleColor(getColorWithAlpha(getResources().getColor(R.color.write_off_rewards_color), 0.4f));
set3.setHighLightColor(getResources().getColor(R.color.write_off_rewards_color));

set1.setMode(LineDataSet.Mode.CUBIC_BEZIER);
set2.setMode(LineDataSet.Mode.CUBIC_BEZIER);
set3.setMode(LineDataSet.Mode.CUBIC_BEZIER);

LineData data = new LineData(set3, set2, set1);

data.setValueTextColor(getResources().getColor(R.color.transparent));

mLineChart.clear();

if (null != mLineChart.getLineData())
    mLineChart.getLineData().clearValues();
mLineChart.setData(data);
mLineChart.getData().notifyDataChanged();
mLineChart.notifyDataSetChanged();
  

Вот средство форматирования:

 public static class ClaimsXAxisValueFormatter extends ValueFormatter {

    List<String> datesList;

    public ClaimsXAxisValueFormatter(List<String> arrayOfDates) {
        this.datesList = arrayOfDates;
    }

    @Override
    public String getAxisLabel(float value, AxisBase axis) {
        int index = Math.round(value);

        if (index < 0 || index >= datesList.size() || index != (int) value)
            return "";
        return datesList.get((int) value);
    }
}
  

Комментарии:

1. Пожалуйста, предоставьте нам какой-нибудь код.

2. @Lilya Вот код, я отредактировал свой пост.

3. Вы задаете пользовательский xAxis.setValueFormatter(new ClaimsXAxisValueFormatter(xValList)); . Пожалуйста, покажите код