当前位置: 首页>>代码示例>>Java>>正文


Java BarData.groupBars方法代码示例

本文整理汇总了Java中com.github.mikephil.charting.data.BarData.groupBars方法的典型用法代码示例。如果您正苦于以下问题:Java BarData.groupBars方法的具体用法?Java BarData.groupBars怎么用?Java BarData.groupBars使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.github.mikephil.charting.data.BarData的用法示例。


在下文中一共展示了BarData.groupBars方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: generateBarData

import com.github.mikephil.charting.data.BarData; //导入方法依赖的package包/类
private BarData generateBarData() {

        ArrayList<BarEntry> entries1 = new ArrayList<BarEntry>();
        ArrayList<BarEntry> entries2 = new ArrayList<BarEntry>();

        for (int index = 0; index < itemcount; index++) {
            entries1.add(new BarEntry(0, getRandom(25, 25)));

            // stacked
            entries2.add(new BarEntry(0, new float[]{getRandom(13, 12), getRandom(13, 12)}));
        }

        BarDataSet set1 = new BarDataSet(entries1, "Bar 1");
        set1.setColor(Color.rgb(60, 220, 78));
        set1.setValueTextColor(Color.rgb(60, 220, 78));
        set1.setValueTextSize(10f);
        set1.setAxisDependency(YAxis.AxisDependency.LEFT);

        BarDataSet set2 = new BarDataSet(entries2, "");
        set2.setStackLabels(new String[]{"Stack 1", "Stack 2"});
        set2.setColors(new int[]{Color.rgb(61, 165, 255), Color.rgb(23, 197, 255)});
        set2.setValueTextColor(Color.rgb(61, 165, 255));
        set2.setValueTextSize(10f);
        set2.setAxisDependency(YAxis.AxisDependency.LEFT);

        float groupSpace = 0.06f;
        float barSpace = 0.02f; // x2 dataset
        float barWidth = 0.45f; // x2 dataset
        // (0.45 + 0.02) * 2 + 0.06 = 1.00 -> interval per "group"

        BarData d = new BarData(set1, set2);
        d.setBarWidth(barWidth);

        // make this BarData object grouped
        d.groupBars(0, groupSpace, barSpace); // start at x = 0

        return d;
    }
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:39,代码来源:CombinedChartActivity.java

示例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);
}
 
开发者ID:liuyongfeng90,项目名称:JKCloud,代码行数:40,代码来源:BarChartManager.java

示例3: testGroupBars

import com.github.mikephil.charting.data.BarData; //导入方法依赖的package包/类
@Test
public void testGroupBars() {

    float groupSpace = 5f;
    float barSpace = 1f;

    List<BarEntry> values1 = new ArrayList<>();
    List<BarEntry> values2 = new ArrayList<>();

    for(int i = 0; i < 5; i++) {
        values1.add(new BarEntry(i, 50));
        values2.add(new BarEntry(i, 60));
    }

    BarDataSet barDataSet1 = new BarDataSet(values1, "Set1");
    BarDataSet barDataSet2 = new BarDataSet(values2, "Set2");

    BarData data = new BarData(barDataSet1, barDataSet2);
    data.setBarWidth(10f);

    float groupWidth = data.getGroupWidth(groupSpace, barSpace);
    assertEquals(27f, groupWidth, 0.01f);

    assertEquals(0f, values1.get(0).getX(), 0.01f);
    assertEquals(1f, values1.get(1).getX(), 0.01f);

    data.groupBars(1000, groupSpace, barSpace);

    // 1000 + 2.5 + 0.5 + 5
    assertEquals(1008f, values1.get(0).getX(), 0.01f);
    assertEquals(1019f, values2.get(0).getX(), 0.01f);
    assertEquals(1035f, values1.get(1).getX(), 0.01f);
    assertEquals(1046f, values2.get(1).getX(), 0.01f);

    data.groupBars(-1000, groupSpace, barSpace);

    assertEquals(-992f, values1.get(0).getX(), 0.01f);
    assertEquals(-981f, values2.get(0).getX(), 0.01f);
    assertEquals(-965f, values1.get(1).getX(), 0.01f);
    assertEquals(-954f, values2.get(1).getX(), 0.01f);

    data.setBarWidth(20f);
    groupWidth = data.getGroupWidth(groupSpace, barSpace);
    assertEquals(47f, groupWidth, 0.01f);

    data.setBarWidth(10f);
    data.groupBars(-20, groupSpace, barSpace);

    assertEquals(-12f, values1.get(0).getX(), 0.01f);
    assertEquals(-1f, values2.get(0).getX(), 0.01f);
    assertEquals(15f, values1.get(1).getX(), 0.01f);
    assertEquals(26f, values2.get(1).getX(), 0.01f);
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:54,代码来源:BarDataTest.java

示例4: onProgressUpdate

import com.github.mikephil.charting.data.BarData; //导入方法依赖的package包/类
@Override
protected void onProgressUpdate(TestCase.Metrics... values) {
    super.onProgressUpdate(values);
    mDataSetIndex = mChart.getData().getIndexOfDataSet(mDataSet);
    if (mDataSetIndex < 0) {
        mChart.getData().addDataSet(mDataSet);
        mDataSetIndex = mChart.getData().getIndexOfDataSet(mDataSet);
    }

    BarData data = mChart.getData();
    for (TestCase.Metrics m : values) {
        data.addEntry(new BarEntry(m.getVariable(), (float) m.getElapsedTime()), mDataSetIndex);
    }
    if (data.getDataSetCount() > 1) {
        int count = data.getDataSetCount();
        float groupSpace = 0.06f;
        float barSpace = 0.02f;
        float numBars = count;
        float barWidth = (1.0f - ((count - 1) * barSpace) - groupSpace) / numBars;

        Collections.sort(
                data.getDataSets(),
                new Comparator<IBarDataSet>() {
                    @Override
                    public int compare(IBarDataSet o1, IBarDataSet o2) {
                        float[] hsl1 = new float[3];
                        float[] hsl2 = new float[3];
                        ColorUtils.colorToHSL(o1.getColor(), hsl1);
                        ColorUtils.colorToHSL(o2.getColor(), hsl2);

                        if (Math.abs(hsl1[0] - hsl2[0]) > 10) {
                            return Float.compare(hsl1[0], hsl2[0]);
                        }

                        if (Math.abs(hsl1[2] - hsl2[2]) > 0.1) {
                            return Float.compare(hsl1[2], hsl2[2]);
                        }

                        return Float.compare(hsl1[1], hsl2[1]);
                    }
                }
        );

        data.setBarWidth(barWidth);
        data.groupBars(2, groupSpace, barSpace);
    }
    mChart.setFitBars(true);
    data.notifyDataChanged();
    mChart.notifyDataSetChanged();
    mChart.invalidate();
}
 
开发者ID:jasonwyatt,项目名称:SQLite-Performance,代码行数:52,代码来源:TestCaseRunner.java


注:本文中的com.github.mikephil.charting.data.BarData.groupBars方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。