我能够使用MPAndroid图表库动态创建折线图,也能够创建折线图的阴影,但我无法在MPAndroid折线图中先前存在的圆孔上创建另一个圆孔?
码
void plotGraph(List<StatementListApi> statementListApis) {
HashMap<Integer, String> stringDoubleHashMap = new HashMap<>();
stringDoubleHashMap.put(0, "0");
stringDoubleHashMap.put(1, "0");
stringDoubleHashMap.put(2, "0");
stringDoubleHashMap.put(3, "0");
stringDoubleHashMap.put(4, "0");
stringDoubleHashMap.put(5, "0");
stringDoubleHashMap.put(6, "0");
for (int i = 0; i < statementListApis.size(); i++) {
Date date = new Date(Long.parseLong(statementListApis.get(i).getRecordedDate()));
System.out.println("date is" + date);
if (stringDoubleHashMap.containsKey(date.getDay())) {
Long aLong = statementListApis.get(i).getAmount() + Long.parseLong(stringDoubleHashMap.get(date.getDay()));
stringDoubleHashMap.put(date.getDay(), aLong + "");
} else {
stringDoubleHashMap.put(date.getDay(), statementListApis.get(i).getAmount() + "");
}
System.out.println("size of hashmap" + stringDoubleHashMap.size());
}
List<String> xVals = new ArrayList<String>(stringDoubleHashMap.values());
List<ILineDataSet> testDataSet1 = new ArrayList<>();
List<Entry> entries = new ArrayList<>();
ArrayList<String> Labels = new ArrayList<>();
Labels.add("SUN");
Labels.add("MON");
Labels.add("TUE");
Labels.add("WED");
Labels.add("THU");
Labels.add("FRI");
Labels.add("SAT");
for (int i = 0; i < xVals.size(); i++) {
entries.add(new Entry(i, Float.parseFloat(xVals.get(i))));
LineDataSet dataSet = new LineDataSet(entries, Labels.get(i));
testDataSet1.add(dataSet);
dataSet.setMode(LineDataSet.Mode.CUBIC_BEZIER);
dataSet.setColor(Color.RED);
dataSet.setCircleColor(Color.WHITE);
dataSet.setValueTextColor(Color.WHITE);
}
activityStatementBinding.lineChart.getXAxis().setTextColor(Color.WHITE);
// for shadow
activityStatementBinding.lineChart.setLayerType(View.LAYER_TYPE_HARDWARE, null);
activityStatementBinding.lineChart.getRenderer().getPaintRender().setShadowLayer(1, 10, 10, Color.BLACK);
IMarker marker = new CustomMarkerView(this, R.layout.activity_marker_view);
activityStatementBinding.lineChart.setMarker(marker);
MarkerImage markerImage = new MarkerImage(this, R.drawable.ic_back_24);
activityStatementBinding.lineChart.setMarker(markerImage);
//Animation
activityStatementBinding.lineChart.animateY(1700);
YAxis leftAxis = activityStatementBinding.lineChart.getAxisRight();
leftAxis.setEnabled(false);
//used to remove the horizontal x-axis lines in graph
YAxis rightAxis = activityStatementBinding.lineChart.getAxisLeft();
rightAxis.setEnabled(false);
activityStatementBinding.lineChart.getDescription().setEnabled(false);
activityStatementBinding.lineChart.getXAxis().setPosition(XAxis.XAxisPosition.BOTTOM);
// used for removing the labels with color
Legend legend = activityStatementBinding.lineChart.getLegend();
legend.setEnabled(false);
// activityStatementBinding.lineChart.moveViewTo(10, 0, RIGHT);
// activityStatementBinding.lineChart.setScrollContainer(true);
// activityStatementBinding.lineChart.setHorizontalScrollBarEnabled(true);
activityStatementBinding.lineChart.getXAxis().setValueFormatter(new IndexAxisValueFormatter(Labels));
activityStatementBinding.lineChart.setData(new LineData(testDataSet1));
activityStatementBinding.lineChart.notifyDataSetChanged();
activityStatementBinding.lineChart.invalidate();
}
获取图像
所需图片
我如何才能在已经存在的圆孔上实现圆孔?
最佳答案
您需要执行以下操作:
lineDataSet.setCircleRadius(6);
float circleHoleRadius = circleRadius/2;
lineDataSet.setCircleHoleRadius(circleHoleRadius);
//lineDataSet.setCircleColor(Color.RED);
// Below line is to add transperancy to your color
lineDataSet.setCircleColor(Color.argb(12,284,55,32));
lineDataSet.setCircleColorHole(Color.WHITE);
您可以根据需要更改颜色和尺寸。快乐的编码:)