首页 > 解决方案 > 如何在 MPandroidCharts 中调整 X-label 文本大小

问题描述

我在 android 应用程序中使用 MPandroidCharts 制作一个条形图,它来自 NodeJs 服务器的数据,我的代码工作正常,但我发现当我更改 nbs 数据(“XAxe 上的文章数”< 5)时,标签 nb 和大小仍然是一些(最多 5 个元素)使我的图表不被理解,我需要一个解决方案 plz

要了解我的情况,请看图片:

在此处输入图像描述

在此处输入图像描述

我的代码:

ArrayList<BarEntry> entries = new ArrayList<>();
            final ArrayList<String> months = new ArrayList<>();
            Log.d("liste size ",product_List.size()+"");
            for(int i=0; i<product_List.size();i++){
                Log.d("get List nb ",product_List.get(i).getId());
                Log.d("get List produit ",product_List.get(i).getProduit());
                months.add(i,product_List.get(i).getProduit());
                int nb = Integer.parseInt(product_List.get(i).getId());
                entries.add(new BarEntry(i, nb));

            }
            BarDataSet barDataSet = new BarDataSet(entries, "Produits");
            barDataSet.setBarBorderWidth(0.9f);
            barDataSet.setColors(ColorTemplate.COLORFUL_COLORS);
            BarData barData = new BarData(barDataSet);
            XAxis xAxis = barChart.getXAxis();
            xAxis.setPosition(XAxis.XAxisPosition.BOTTOM);

            IndexAxisValueFormatter formatter = new IndexAxisValueFormatter(months);
            xAxis.setGranularity(1f);
            xAxis.setValueFormatter(formatter);
            barChart.setData(barData);
            barChart.setFitBars(true);
            barChart.animateY(5000);
            barChart.invalidate();

还有一件事,如果我什么时候清除图表数据并通过一个按钮让其他人使用我需要使用的代码。

标签: androidmpandroidchart

解决方案


推荐阅读