帮我生成一份条形统计图的安卓代码
时间: 2023-07-10 11:06:15 浏览: 45
好的,我可以提供一个简单的安卓条形统计图代码示例,但需要您提供一些数据和具体需求,例如图表中要显示哪些数据、颜色、字体等。以下是一个示例代码:
```
public class BarChartActivity extends AppCompatActivity {
private BarChart mBarChart;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_bar_chart);
mBarChart = findViewById(R.id.bar_chart);
ArrayList<BarEntry> entries = new ArrayList<>();
// 添加数据
entries.add(new BarEntry(1, 20));
entries.add(new BarEntry(2, 30));
entries.add(new BarEntry(3, 40));
entries.add(new BarEntry(4, 50));
entries.add(new BarEntry(5, 60));
BarDataSet dataSet = new BarDataSet(entries, "Bar Chart");
// 设置颜色
dataSet.setColor(Color.BLUE);
BarData barData = new BarData(dataSet);
mBarChart.setData(barData);
// 设置字体大小
mBarChart.getXAxis().setTextSize(12f);
mBarChart.getAxisLeft().setTextSize(12f);
mBarChart.getLegend().setTextSize(12f);
mBarChart.invalidate();
}
}
```
这段代码会生成一个简单的条形统计图,数据为 20,30,40,50 和 60。您可以根据自己的需求修改这些数据和样式。希望能对您有所帮助!
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)