作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我能够使用 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();
}
How can i achieve the circle hole over the one that already exist?
最佳答案
您需要执行以下操作:
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);
您可以根据需要更改颜色和尺寸。快乐编码:)
关于android - 我可以在 MpAndroid 折线图中已经存在的圆孔上创建一个圆孔吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48364156/
我是一名优秀的程序员,十分优秀!