android中的MPAndroidChart条形图问题

时间:2017-04-25 07:00:50

标签: android mpandroidchart

我正在使用MPAndroidChart

  • 如何在Horizo​​ntalBarChart中将BarEntryLabel更改为左?v如何从底部删除项目? enter image description here
  • 如何禁用缩放?
  • 点击特定的条形颜色正在改变如何禁用它?
  • 在BarChart,我已经增加了6个月但是EntryLabels未正确对齐到相应的栏。enter image description here

代码:

 BARENTRY = new ArrayList<>();
    BarEntryLabels = new ArrayList<String>();
    AddValuesToBARENTRY();
    AddValuesToBarEntryLabels();
    Bardataset = new BarDataSet(BARENTRY, "Projects");
    BARDATA = new BarData(BarEntryLabels, Bardataset);
    Bardataset.setColors(new int[]{Color.parseColor("#701112")});
    horizontalBarChart.setData(BARDATA);
    horizontalBarChart.setDrawBarShadow(false);
    horizontalBarChart.setDrawValueAboveBar(true);
    // if more than 60 entries are displayed in the chart, no values will be
    // drawn
    horizontalBarChart.setMaxVisibleValueCount(60);
    // scaling can now only be done on x- and y-axis separately
    horizontalBarChart.setPinchZoom(false);
    // draw shadows for each bar that show the maximum value
    // mChart.setDrawBarShadow(true);
    horizontalBarChart.setDrawGridBackground(false);
    horizontalBarChart.setDescription("");
    Bardataset.setBarSpacePercent(10f);


    barChart.setData(BARDATA);
    barChart.setDrawBarShadow(false);
    barChart.setDrawValueAboveBar(true);
    // if more than 60 entries are displayed in the chart, no values will be
    // drawn
    barChart.setMaxVisibleValueCount(60);
    // scaling can now only be done on x- and y-axis separately
    barChart.setPinchZoom(false);
    // draw shadows for each bar that show the maximum value
    // mChart.setDrawBarShadow(true);
    barChart.setDrawGridBackground(false);
    barChart.setDescription("");

2 个答案:

答案 0 :(得分:1)

对于&#34;项目&#34; 图例部分,请尝试此

  Legend legend = mBarChart.getLegend();
  legend.setEnabled(false);

要在条形图对象上进行触摸禁用设置 setTouchEnabled(布尔启用) ,就像这样

  mBarChart.setTouchEnabled(false);

如果您想显示所有标签,请尝试

  axis.setLabelCount(...)
  mBarChart.getXAxis().setValueFormatter(new IndexAxisValueFormatter(labels));

并尝试official documents

答案 1 :(得分:0)

  BARENTRY1 = new ArrayList<>();
    BarEntryLabels1 = new ArrayList<String>();
    AddValuesToHorizontalBARENTRY();
    AddValuesToHorizontalBarEntryLabels();
    Bardataset = new BarDataSet(BARENTRY1, "Projects");
    BARDATA = new BarData(BarEntryLabels1, Bardataset);
    Bardataset.setColors(new int[]{Color.parseColor("#701112")});
    horizontalBarChart.setData(BARDATA);
    horizontalBarChart.setDrawBarShadow(false);
    horizontalBarChart.setDrawValueAboveBar(true);
    horizontalBarChart.setPinchZoom(false);
    horizontalBarChart.setDrawGridBackground(false);
    horizontalBarChart.setDescription("");
    Bardataset.setBarSpacePercent(10f);
    Legend legend = horizontalBarChart.getLegend();
    legend.setEnabled(false);
    horizontalBarChart.setTouchEnabled(false);
    XAxis xAxis1 = horizontalBarChart.getXAxis();
    xAxis1.setPosition(XAxis.XAxisPosition.BOTTOM);
    xAxis1.setTextSize(8);
    xAxis1.setSpaceBetweenLabels(8);
    xAxis1.setTextColor(Color.parseColor("#701112"));
    xAxis1.setTypeface(tf);
    YAxis leftAxis = barChart.getAxisLeft();
    leftAxis.setEnabled(false);

这样做。以下问题将得到解决。