Sunisha Guptan
Sunisha Guptan

Reputation: 1605

MPAndroidChart bar chart issues in android

I am using MPAndroidChart.

Code:

 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("");

Upvotes: 0

Views: 1223

Answers (2)

Sunisha Guptan
Sunisha Guptan

Reputation: 1605

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

Do like this.The following issue will be fix.

Upvotes: 0

Somesh Kumar
Somesh Kumar

Reputation: 8638

For the "project" legend part try this

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

To make touch disable set setTouchEnabled(boolean enabled) on your bar chart object like this

  mBarChart.setTouchEnabled(false);

and if you want to show all label you should try

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

and also try official documents

Upvotes: 1

Related Questions