我想在我的 Android 应用程序中显示一个带有工具提示功能的堆积条形图。我使用 MarkerView 显示它但没有成功。这是示例代码。
我也在传奇中面临问题..!由于库不支持文本换行,因此未显示图例。Y 轴的值以整数显示。我想在浮动中显示。我可以在 Y 轴值中给出“%”吗?像这样的东西,
chart1 = (BarChart) findViewById(R.id.chart1);
chart1.setDrawYValues(true);
//chart1.setDrawValueAboveBar(true);
chart1.setDescription("");
chart1.set3DEnabled(false);
chart1.setUnit("%");
chart1.setDrawGridBackground(false);
chart1.setDrawHorizontalGrid(true);
chart1.setValueTextSize(8f);
chart1.setDrawBorder(false);
chart1.setYRange(0.0f,100.0f,true);
chart1.setDrawLegend(true);
chart1.setPinchZoom(true);
chart1.setTouchEnabled(true);
//Code for Tooltip at barchart.
/*MyMarkerView mv = new MyMarkerView(getApplicationContext(), R.layout.custom_marker_view);
mv.setOffsets(-mv.getMeasuredWidth() / 2, -mv.getMeasuredHeight());
chart1.setMarkerView(mv);*/
XLabels xl = chart1.getXLabels();
xl.setPosition(XLabels.XLabelPosition.BOTTOM);
xl.setSpaceBetweenLabels(10);
xl.setCenterXLabelText(true);
YLabels yl = chart1.getYLabels();
//yl.setLabelCount(10);
yl.setPosition(YLabels.YLabelPosition.LEFT);
setData();
Legend l = chart1.getLegend();
l.setPosition(Legend.LegendPosition.BELOW_CHART_RIGHT);
l.setFormSize(8f);
l.setYEntrySpace(4f);
chart1.animateY(3000);
}
} catch (JSONException e) {
// TODO Auto-generated catch block
Toast.makeText(getApplicationContext(), "Error Occurred [Server's JSON response might be invalid]!" + e.getMessage(), Toast.LENGTH_LONG).show();
e.printStackTrace();
}
}
private void setData() {
ArrayList<String> xVals = new <String>ArrayList<String>();
xVals.add("Donors");
xVals.add("Amount");
ArrayList<BarEntry> yVals1 = new <BarEntry>ArrayList<BarEntry>();
yVals1.add(new BarEntry(new float[]{donoravg.get(0),donoravg.get(1),donoravg.get(2),donoravg.get(3),donoravg.get(4),donoravg.get(5),donoravg.get(6),donoravg.get(7),donoravg.get(8),donoravg.get(9),donoravg.get(10)}, 0));
yVals1.add(new BarEntry(new float[]{amountavg.get(0),amountavg.get(1),amountavg.get(2),amountavg.get(3),amountavg.get(4),amountavg.get(5),amountavg.get(6),amountavg.get(7),amountavg.get(8),amountavg.get(9)}, 1));
BarDataSet set1 = new BarDataSet(yVals1, "");
set1.setStackLabels(new String[]{"All other defector count", "Last Year Defector Count", "At Risk Donor Count"});
set1.setBarSpacePercent(40f);
set1.setColors(new int[]{R.color.pink_400, R.color.purple_300, R.color.deep_purple_300, R.color.indigo_300, R.color.cyan_300, R.color.teal_300, R.color.amber_300, R.color.deep_orange_300, R.color.brown_300, R.color.blue_grey_300}, getApplicationContext());
ArrayList<BarDataSet> dataSets = new <BarDataSet>ArrayList<BarDataSet>();
dataSets.add(set1);
BarData data = new BarData(xVals, dataSets);
chart1.setData(data);
}