java - 删除 MPAndroidChart 中的 BarDataSet

标签 java android mpandroidchart

我正在使用 MPAndroidChart 构建 BarChart,但我无法设置我的 BarDataSet(1) 并设置我的列的内容( 2) 垂直。有人可以帮忙吗?

enter image description here

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);
}

最佳答案

是的,可以,只需使用以下代码:

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;

并尝试此代码栏数据集再次不可见

关于java - 删除 MPAndroidChart 中的 BarDataSet,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49441653/

相关文章:

java - 无法解析带时区的日期

android - MPAndroidChart 是否支持堆叠条形图?

java - 使用循环添加具有随机变量的对象

java - Apache commons CLI 的条件命令行选项

java - 如何调整项目选择器 xml 中的图像大小

android - MPAndroidChart - MarkerView 不显示阴影

android - MPAndroidChart 中折线图上的数据点被裁剪

java - Hibernate 映射通过引用未知目标实体

java - 如何连接到 Android 应用程序 (Java) 中的 Rails SSE 流页面?

android - ReST API 安全性