本文整理汇总了Java中com.github.mikephil.charting.data.BarData.addDataSet方法的典型用法代码示例。如果您正苦于以下问题:Java BarData.addDataSet方法的具体用法?Java BarData.addDataSet怎么用?Java BarData.addDataSet使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.github.mikephil.charting.data.BarData
的用法示例。
在下文中一共展示了BarData.addDataSet方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: generateBarData
import com.github.mikephil.charting.data.BarData; //导入方法依赖的package包/类
/**
* 柱形图数据
*/
private BarData generateBarData() {
BarData barData = new BarData();
ArrayList<BarEntry> entries1 = new ArrayList<>();
for (int index = 0; index < items.size(); index++) {
entries1.add(new BarEntry(index + 1f, (float) items.get(index).main_data.getData()));
}
BarDataSet barDataSet = new BarDataSet(entries1, "当前数据");
barDataSet.setValues(entries1);
barDataSet.setDrawValues(false);//是否在线上显示值
barDataSet.setColor(Color.rgb(230, 230, 230));
barDataSet.setHighLightColor(Color.parseColor(items.get(dateSelected).state.getColor()));
barDataSet.setValueTextColor(Color.rgb(60, 220, 78));
barDataSet.setValueTextSize(10f);
barDataSet.setAxisDependency(YAxis.AxisDependency.LEFT);
float barWidth = 0.45f;
barData.addDataSet(barDataSet);
barData.setBarWidth(barWidth);
return barData;
}
示例2: showBarChart
import com.github.mikephil.charting.data.BarData; //导入方法依赖的package包/类
/**
* 展示柱状图(多条)
*
* @param xAxisValues
* @param yAxisValues
* @param labels
* @param colours
*/
public void showBarChart(List<Float> xAxisValues, List<List<Float>> yAxisValues, List<String> labels, List<Integer> colours) {
initLineChart();
BarData data = new BarData();
for (int i = 0; i < yAxisValues.size(); i++) {
ArrayList<BarEntry> entries = new ArrayList<>();
for (int j = 0; j < yAxisValues.get(i).size(); j++) {
entries.add(new BarEntry(xAxisValues.get(j), yAxisValues.get(i).get(j)));
}
BarDataSet barDataSet = new BarDataSet(entries, labels.get(i));
barDataSet.setColor(colours.get(i));
barDataSet.setValueTextColor(colours.get(i));
barDataSet.setValueTextSize(10f);
barDataSet.setAxisDependency(YAxis.AxisDependency.LEFT);
data.addDataSet(barDataSet);
}
int amount = yAxisValues.size();
float groupSpace = 0.12f; //柱状图组之间的间距
float barSpace = (float) ((1 - 0.12) / amount / 10); // x4 DataSet
float barWidth = (float) ((1 - 0.12) / amount / 10 * 9); // x4 DataSet
// (0.2 + 0.02) * 4 + 0.08 = 1.00 -> interval per "group"
xAxis.setLabelCount(xAxisValues.size() - 1, false);
data.setBarWidth(barWidth);
data.groupBars(0, groupSpace, barSpace);
mBarChart.setData(data);
}
示例3: createBarChart
import com.github.mikephil.charting.data.BarData; //导入方法依赖的package包/类
/**
* Creates the bar chart showing counters visually.
*/
private void createBarChart(BarChart barChart) {
if (game != null) {
ArrayList<BarEntry> entries = new ArrayList<>();
ArrayList<BarEntry> entries2 = new ArrayList<>();
// create simple bar chart
// fill single rolls, 1..6
int[] counts = sr.getCounts();
for (int i = 0; i < counts.length; i++) {
entries.add(new BarEntry(counts[i], i));
}
// fill double roll sums, 2..12
counts = dr.getSumCount();
for (int i = 0; i < counts.length; i++) {
entries2.add(new BarEntry(counts[i], i + 1));
}
BarDataSet dataset = new BarDataSet(entries, "# of single rolls: " + sr.getTotal());
BarDataSet dataset2 = new BarDataSet(entries2, "# of double rolls: " + dr.getTotal());
ArrayList<String> labels = new ArrayList<>();
// fill label for dice roll sums, 1..12
for (int i = 0; i < 12; i++) {
labels.add(Integer.toString(i + 1));
}
// explicit color resolving with util, see AboutActivity#demoBarChart
List<Integer> colors = ColorTemplate.createColors(getResources(), new int[]{R.color.colorSingleRoll, R.color.colorDoubleRoll});
//dataset.setColors(ColorTemplate.COLORFUL_COLORS);
dataset.setColor(colors.get(0));
dataset2.setColor(colors.get(1));
BarData data = new BarData(labels, dataset);
data.addDataSet(dataset2);
barChart.setData(data);
}
}
示例4: generateBarData
import com.github.mikephil.charting.data.BarData; //导入方法依赖的package包/类
private BarData generateBarData(float index, float dis) {
ArrayList<BarEntry> entries = new ArrayList<>();
for (int i = 0; i < count; i++) {
float a = new Random().nextInt(40) / 100f + 0.1f;
float b = new Random().nextInt(40) / 100f + 0.1f;
entries.add(new BarEntry(index, new float[]{a, b, 1 - a - b}));
index += dis;
}
BarDataSet set = new BarDataSet(entries, "hello");
set.setStackLabels(new String[]{"1", "2"});
set.setColors(new int[]{Color.rgb(154, 209, 253), Color.rgb(254, 206, 121), Color.rgb(253, 136, 95)});
set.setValueTextColor(Color.rgb(61, 165, 255));
set.setValueTextSize(10f);
set.setAxisDependency(YAxis.AxisDependency.LEFT);
ArrayList<IBarDataSet> threebardata = new ArrayList<>();
BarData d = new BarData(threebardata);
d.setBarWidth(0.4f);
d.setDrawValues(true);
d.addDataSet(set);
d.setValueFormatter(new IValueFormatter() {
@Override
public String getFormattedValue(float value, Entry entry, int dataSetIndex, ViewPortHandler viewPortHandler) {
return toPercentDecimalStr(value);
}
});
return d;
}
示例5: setUp
import com.github.mikephil.charting.data.BarData; //导入方法依赖的package包/类
@Before
public void setUp() {
mockStatic(android.graphics.Color.class);
when(android.graphics.Color.rgb(anyInt(), anyInt(), anyInt())).thenReturn(0);
barData = new BarData();
barData.setBarWidth((1f - HistogramChart.GROUP_SPACE)/1);
barData.addDataSet(new BarDataSet(new ArrayList<BarEntry>(), "SomeLabel"));
data = new HistogramChart.HistogramData(1, 5f);
data.addEntry(barData, 0, 12);
data.addEntry(barData, 0, 14);
data.addEntry(barData, 0, 16);
data.addEntry(barData, 0, 21);
}
示例6: addDataSet
import com.github.mikephil.charting.data.BarData; //导入方法依赖的package包/类
private void addDataSet(GraphData graphData) {
Log.e("yangjun", "----- addDataSet ----");
BarData barData = partBartChart.getData();
if (barData != null) {
Log.e("yangjun", "----- clear values ----");
barData.clearValues();
}
List<Partition> partitions = graphData.getPartitions();
// READ
ArrayList<BarEntry> yVals1 = new ArrayList<BarEntry>();
for (int i = 0; i < partitions.size(); i++) {
yVals1.add(new BarEntry(partitions.get(i).readLogs.size(), i));
}
// WRITE
ArrayList<BarEntry> yVals2 = new ArrayList<BarEntry>();
for (int i = 0; i < partitions.size(); i++) {
yVals2.add(new BarEntry(partitions.get(i).writeLogs.size(), i));
}
BarDataSet set1 = new BarDataSet(yVals1, "READ");
set1.setColor(Color.rgb(104, 241, 175));
set1.setValueFormatter(new LargeValueFormatter());
BarDataSet set2 = new BarDataSet(yVals2, "WRITE");
set2.setColor(Color.rgb(164, 228, 251));
set2.setValueFormatter(new LargeValueFormatter());
barData.addDataSet(set1);
barData.addDataSet(set2);
partBartChart.notifyDataSetChanged();
partBartChart.invalidate();
}
示例7: generateBarData
import com.github.mikephil.charting.data.BarData; //导入方法依赖的package包/类
private BarData generateBarData() {
BarData d = new BarData();
ArrayList<BarEntry> entries = new ArrayList<BarEntry>();
for (int index = 0; index < itemcount; index++)
entries.add(new BarEntry(getRandom(15, 30), index));
BarDataSet set = new BarDataSet(entries, "Bar DataSet");
set.setColor(Color.rgb(60, 220, 78));
set.setValueTextColor(Color.rgb(60, 220, 78));
set.setValueTextSize(10f);
d.addDataSet(set);
set.setAxisDependency(YAxis.AxisDependency.LEFT);
return d;
}