我创建了一个图表,显示x轴的字符串和y轴的美元。我能够在图表上看到这些值,但我的数据太多而无法在图表上显示。
图表是可滚动的,所以我想在条形图上显示最小数量的值,如下图所示。
但是现在我在图中得到了太多的条形图:
这是我的代码:
public void setGraph() {
if (sessionData.getString("graphType", "").equals("d") || sessionData.getString("graphType", "").equals("m"))
{
int index = 0;
String[] dates = new String[totalOrdersList.size()];
mChart.setDrawBarShadow(false);
mChart.setDrawValueAboveBar(false);
mChart.getDescription().setEnabled(false);
mChart.setBackgroundColor(ContextCompat.getColor(getActivity(), R.color.lightGrey));
// mChart.setScaleEnabled(false);
// if more than 60 entries are displayed in the chart, no values will be
// drawn
mChart.setMaxVisibleValueCount(60);
// scaling can now only be done on x- and y-axis separately
mChart.setPinchZoom(false);
mChart.setDrawGridBackground(false);
// mChart.setDrawYLabels(false);
IndexAxisValueFormatter xAxisFormatter = new IndexAxisValueFormatter(dates);
XAxis xAxis = mChart.getXAxis();
xAxis.setPosition(XAxis.XAxisPosition.BOTTOM);
xAxis.setDrawGridLines(false);
xAxis.setLabelCount(3);
xAxis.setValueFormatter(xAxisFormatter);
xAxis.setGranularity(1f);
com.github.mikephil.charting.formatter.IAxisValueFormatter custom = new MyAxisValueFormatter();
YAxis leftAxis = mChart.getAxisLeft();
leftAxis.setLabelCount(8, false);
leftAxis.setValueFormatter(custom);
leftAxis.setPosition(YAxis.YAxisLabelPosition.OUTSIDE_CHART);
leftAxis.setSpaceTop(15f);
leftAxis.setAxisMinimum(0f); // this replaces setStartAtZero(true)
YAxis rightAxis = mChart.getAxisRight();
rightAxis.setDrawGridLines(false);
rightAxis.setLabelCount(8, false);
rightAxis.setValueFormatter(custom);
rightAxis.setSpaceTop(15f);
rightAxis.setAxisMinimum(0f);
rightAxis.setEnabled(false);
// this replaces setStartAtZero(true)
Legend l = mChart.getLegend();
l.setVerticalAlignment(Legend.LegendVerticalAlignment.BOTTOM);
l.setHorizontalAlignment(Legend.LegendHorizontalAlignment.LEFT);
l.setOrientation(Legend.LegendOrientation.HORIZONTAL);
l.setDrawInside(false);
l.setForm(Legend.LegendForm.SQUARE);
l.setFormSize(9f);
l.setTextSize(11f);
l.setXEntrySpace(4f);
ArrayList<BarEntry> barEntries = new ArrayList<>();
for (Order o : totalOrdersList) {
dates[index] = o.getDate();
barEntries.add(new BarEntry(index, Float.parseFloat(o.getAmount())));
index++;
}
BarDataSet set1 = new BarDataSet(barEntries, "Months");
set1.setValues(barEntries);
set1.setColor(ContextCompat.getColor(getActivity(), R.color.orange));
ArrayList<IBarDataSet> dataSets = new ArrayList<IBarDataSet>();
dataSets.add(set1);
BarData data = new BarData(dataSets);
data.setValueTextSize(10f);
data.setBarWidth(0.9f);
mChart.setData(data);
mChart.animateXY(3000, 3000);
}
请帮忙......谢谢..