android - 如何在 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();
还有一件事,如果我什么时候清除图表数据并通过一个按钮让其他人使用我需要使用的代码。
解决方案
推荐阅读
- sql - postgres pg_statio:heap_blks_hit 和 idx_blks_hit 之间的区别
- javascript - promise.then() 返回 Promise {
} - java - 处理 AWS Amplify onError 回调异常
- r - 如何将因子变量计算到回归模型中?
- python - 导入 Python Tkinter 脚本会更改默认单选按钮值
- sql - 如何在 PostgreSQL 中的多个有序列上获取具有最大值的行?
- javascript - 由 ajax 交付时,用于填充模式内容的引导 jquery 不会触发
- c++ - 为什么 std::extent 不能对像 operator sizeof 这样的数组的引用起作用?
- email - 缺少引用和回复标头时有关电子邮件线程的问题
- c# - .NET Core 3.1 中是否存在 HTTPResponse 响应