MPAndroidChart icon indicating copy to clipboard operation
MPAndroidChart copied to clipboard

HorizontalBarChart values not showing (v3.0.1)

Open aleigood opened this issue 7 years ago • 5 comments

The test code:

    mChart = (HorizontalBarChart) findViewById(R.id.chart);
    mChart.getDescription().setEnabled(false);
    mChart.setMaxVisibleValueCount(30);
    mChart.setPinchZoom(true);
    mChart.setDoubleTapToZoomEnabled(false);
    mChart.setDrawGridBackground(false);
    mChart.setHighlightPerTapEnabled(false);
    mChart.getAxisLeft().setEnabled(false);
    mChart.getAxisRight().setEnabled(false);
    mChart.setFitBars(true);
    mChart.animateY(1000);
    final ArrayList<BarEntry> values = new ArrayList<>();
    values.add(new BarEntry(0, 1, "1"));
    values.add(new BarEntry(1, 4, "2"));
    values.add(new BarEntry(2, 7, "3"));
    values.add(new BarEntry(3, 7, "4"));
    values.add(new BarEntry(4, 7, "5"));
    values.add(new BarEntry(5, 4, "6"));
    values.add(new BarEntry(6, 3, "7"));
    values.add(new BarEntry(7, 20, "8"));

    BarDataSet dataSet = new BarDataSet(values, "Test");
    ArrayList<Integer> colors = new ArrayList<>();
    for (int c : ColorTemplate.VORDIPLOM_COLORS)
        colors.add(c);

    for (int c : ColorTemplate.JOYFUL_COLORS)
        colors.add(c);

    for (int c : ColorTemplate.COLORFUL_COLORS)
        colors.add(c);

    for (int c : ColorTemplate.LIBERTY_COLORS)
        colors.add(c);

    for (int c : ColorTemplate.PASTEL_COLORS)
        colors.add(c);
    colors.add(ColorTemplate.getHoloBlue());
    dataSet.setColors(colors);
    dataSet.setDrawValues(true);
    dataSet.setValueTextSize(14f);
    dataSet.setValueTextColor(ContextCompat.getColor(this, R.color.primary_text_color));
    dataSet.setHighlightEnabled(false);
    dataSet.setValueFormatter(new IValueFormatter() {
        @Override
        public String getFormattedValue(float value, Entry entry, int dataSetIndex, ViewPortHandler viewPortHandler) {
            return (int) value + "";
        }
    });

    ArrayList<IBarDataSet> dataSets = new ArrayList<>();
    dataSets.add(dataSet);
    BarData barData = new BarData(dataSets);

    XAxis xl = mChart.getXAxis();
    xl.setTextColor(ContextCompat.getColor(this, R.color.primary_text_color));
    xl.setTextSize(14f);
    xl.setLabelCount(values.size());
    xl.setDrawLabels(true);
    xl.setPosition(XAxis.XAxisPosition.BOTTOM);
    xl.setDrawAxisLine(true);
    xl.setDrawGridLines(false);
    xl.setGranularity(1f);
    xl.setValueFormatter(new IAxisValueFormatter() {
        @Override
        public String getFormattedValue(float value, AxisBase axis) {
            return values.get((int) value).getData().toString();
        }
    });

    mChart.setData(barData);
    mChart.invalidate();

2017-03-16_105139

when I change the values.add(new BarEntry(7, 20, "8")); to values.add(new BarEntry(7, 6, "8")); the values is invisible: 2017-03-16_105108

aleigood avatar Mar 16 '17 02:03 aleigood

i have the problem , please help me if you have any solution

oduysmara avatar Jul 05 '17 05:07 oduysmara

+1

delox avatar Jan 20 '18 23:01 delox

Is this fixed?. i am facing same issue

ashokreddy-narra avatar May 21 '19 15:05 ashokreddy-narra

+1

bakonMa avatar Nov 20 '19 07:11 bakonMa

+1

KikisHuang avatar Jul 13 '22 07:07 KikisHuang