问题描述
如何使用
我编辑了一个代码,我从github的一个示例项目中获得了代码。
如何将 100f和110f
值放在一个 Xaxis
标签整个数字
得分1 =新得分(100f,0,Whole Number);
mRealm.copyToRealm(score1);
分数score2 =新分数(110f,0,整数);
mRealm.copyToRealm(score2);
是的, p>
你需要的是一个 BarChart
和多个 BarDataSets
,其中每个设置(在你的情况下)代表一种性别(男性或女性)。
- 以下是
- 以下是
示例代码(不包括realm.io)
列表< String> xValues = ...; //丹麦,芬兰,...
XAxis xAxis = chart.getXAxis();
xAxis.setValueFormatter(new MyValueFormatter(xValues));
//创建2个数据集
BarDataSet set1 = new BarDataSet(valuesMen,Men);
set1.setColor(Color.BLUE);
BarDataSet set2 = new BarDataSet(valuesWomen,Women);
set2.setColor(Color.RED);
BarData data = new BarData(set1,set2);
chart.setData(data);
chart.groupBars(...); //自发布v3.0.0以后可用
chart.invalidate(); //刷新
如果您需要进一步的帮助,请使用关于Wiki上提供的 BarChart
。
如果您想将 BarChart
中的值叠到彼此之上,您需要创建一个堆叠-barchart:
How can i compare two set of data using BarChart
of MPAndroidChart.
It should look like this image below:
I edited a code, I get from a sample project in github.how can I put together 100f and 110f
value in one Xaxis
label Whole Number
Score score1 = new Score(100f, 0, "Whole Number");
mRealm.copyToRealm(score1);
Score score2 = new Score(110f, 0, "Whole Number");
mRealm.copyToRealm(score2);
Yes, that can be done quite easily.
What you need is a BarChart
with multiple BarDataSets
where each set (in your case) represents one sex (men or women).
- Here is an example of how to create a BarChart with multiple DataSets
- Here is an tutorial of how to use MPAndroidChart with Realm.io
Example code (without realm.io)
List<String> xValues = ...; // "Denmark", "Finland", ...
XAxis xAxis = chart.getXAxis();
xAxis.setValueFormatter(new MyValueFormatter(xValues));
// create 2 datasets
BarDataSet set1 = new BarDataSet(valuesMen, "Men");
set1.setColor(Color.BLUE);
BarDataSet set2 = new BarDataSet(valuesWomen, "Women");
set2.setColor(Color.RED);
BarData data = new BarData(set1, set2);
chart.setData(data);
chart.groupBars(...); // available since release v3.0.0
chart.invalidate(); // refresh
If you need further assistance, here is a detailed tutorial on grouped BarChart
available on the wiki.
If you want to "stack" values in a BarChart
above each other, you need to create a stacked-barchart: Android Stacked Bars Chart
这篇关于如何用MPAndroidChart分组条形图创建BarChart?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!