我使用MPAndroidChart
构建BarChart
,但我无法设置BarDataSet
(1)并设置我的专栏内容(2) )到垂直。有人可以帮忙吗?
public void LoadChart(final ArrayList<String> nameDate, ArrayList<Float> fl){
com.github.mikephil.charting.charts.BarChart chart = (com.github.mikephil.charting.charts.BarChart) findViewById(R.id.barchart);
/* final String[] nameDate={"JAN","FEB","MAR","APR","MAY","JUN"};
Float[] fl = new Float[]{30f,80f,60f,50f,70f,60f};*/
List<BarEntry> entries = new ArrayList<>();
for(int i=0;i<fl.size();i++)
{
entries.add(new BarEntry(i, fl.get(i)));
}
mDB.open();
BarDataSet set = new BarDataSet(entries, "BarDataSet");
set.setColor(Color.rgb(103,203,27));
BarData data = new BarData(set);
data.setBarWidth(0.9f); // set custom bar width
chart.setData(data);
chart.setFitBars(true); // make the x-axis fit exactly all bars
chart.animateXY(2000, 2000);
chart.setScaleEnabled(false);
chart.invalidate(); // refresh
Description description = chart.getDescription();
description.setEnabled(false);
XAxis xAxis = chart.getXAxis();
xAxis.setDrawGridLines(false);
xAxis.setPosition(XAxis.XAxisPosition.BOTTOM);
xAxis.setDrawGridLines(false);
xAxis.setGranularity(1f);
xAxis.setValueFormatter(new IAxisValueFormatter() {
@Override
public String getFormattedValue(float value, AxisBase axis) {
return nameDate.get((int) value);
}
});
YAxis yLabels = chart.getAxisLeft();
yLabels.setDrawGridLines(false);
YAxis yLabels1 = chart.getAxisRight();
yLabels1.setEnabled(false);
}
答案 0 :(得分:0)
是的,可以,只需使用以下代码:
mChart.setDescription(""); // Hide the description
mChart.getAxisLeft().setDrawLabels(false);
mChart.getAxisRight().setDrawLabels(false);
mChart.getXAxis().setDrawLabels(false);
mChart.getLegend().setEnabled(false);
试试这个
或强>
pieChart.setUsePercentValues(true);
pieChart.getDescription().setEnabled(false);
pieChart.setExtraOffsets(0, 0, 0,0 );
pieChart.setDragDecelerationFrictionCoef(0.95f);
mChart.setCenterTextTypeface(mTfLight);
mChart.setCenterText(generateCenterSpannableText());
pieChart.setDrawHoleEnabled(false);
// mChart.setHoleColor(Color.WHITE);
// mChart.setTransparentCircleColor(Color.WHITE);
// mChart.setTransparentCircleAlpha(110);
// mChart.setHoleRadius(58f);
// mChart.setTransparentCircleRadius(61f);
pieChart.setDrawCenterText(false);
pieChart.setRotationAngle(0);
// enable rotation of the chart by touch
pieChart.setRotationEnabled(false);
pieChart.setHighlightPerTapEnabled(false);
// mChart.setUnit(" €");
// mChart.setDrawUnitsInChart(true);
// add a selection listener
pieChart.setOnChartValueSelectedListener(this);
setData(4, 100);
pieChart.animateY(0, Easing.EasingOption.EaseInOutQuad);
// mChart.spin(2000, 0, 360);
// mSeekBarX.setOnSeekBarChangeListener(this);
// mSeekBarY.setOnSeekBarChangeListener(this);
Legend l = pieChart.getLegend();
l.setVerticalAlignment(Legend.LegendVerticalAlignment.TOP);
l.setHorizontalAlignment(Legend.LegendHorizontalAlignment.RIGHT);
l.setOrientation(Legend.LegendOrientation.VERTICAL);
l.setDrawInside(false);
l.setXEntrySpace(7f);
l.setYEntrySpace(0f);
l.setYOffset(0f);
// mChart.setDescription(""); // Hide the description
// mChart.getAxisLeft().setDrawLabels(false);
// mChart.getAxisRight().setDrawLabels(false);
// mChart.getXAxis().setDrawLabels(false);
pieChart.getLegend().setEnabled(false); // Hi
// entry label styling
pieChart.setEntryLabelColor(Color.WHITE);
// mChart.setEntryLabelTypeface(mTfRegular);
pieChart.setEntryLabelTextSize(12f);
return rootView;
并尝试此代码栏数据集再次不可见