/** * Groups all BarDataSet objects this data object holds together by modifying the x-value of their entries. * Previously set x-values of entries will be overwritten. Leaves space between bars and groups as specified * by the parameters. * Calls notifyDataSetChanged() afterwards. * * @param fromX the starting point on the x-axis where the grouping should begin * @param groupSpace the space between groups of bars in values (not pixels) e.g. 0.8f for bar width 1f * @param barSpace the space between individual bars in values (not pixels) e.g. 0.1f for bar width 1f */ public void groupBars(float fromX, float groupSpace, float barSpace) { if (getBarData() == null) { throw new RuntimeException("You need to set data for the chart before grouping bars."); } else { getBarData().groupBars(fromX, groupSpace, barSpace); notifyDataSetChanged(); } } }
chart.getBarData().setBarWidth(barWidth); chart.getXAxis().setAxisMaximum(startYear + chart.getBarData().getGroupWidth(groupSpace, barSpace) * groupCount); chart.groupBars(startYear, groupSpace, barSpace); chart.invalidate();
/** * Groups all BarDataSet objects this data object holds together by modifying the x-value of their entries. * Previously set x-values of entries will be overwritten. Leaves space between bars and groups as specified * by the parameters. * Calls notifyDataSetChanged() afterwards. * * @param fromX the starting point on the x-axis where the grouping should begin * @param groupSpace the space between groups of bars in values (not pixels) e.g. 0.8f for bar width 1f * @param barSpace the space between individual bars in values (not pixels) e.g. 0.1f for bar width 1f */ public void groupBars(float fromX, float groupSpace, float barSpace) { if (getBarData() == null) { throw new RuntimeException("You need to set data for the chart before grouping bars."); } else { getBarData().groupBars(fromX, groupSpace, barSpace); notifyDataSetChanged(); } } }
/** * Groups all BarDataSet objects this data object holds together by modifying the x-value of their entries. * Previously set x-values of entries will be overwritten. Leaves space between bars and groups as specified * by the parameters. * Calls notifyDataSetChanged() afterwards. * * @param fromX the starting point on the x-axis where the grouping should begin * @param groupSpace the space between groups of bars in values (not pixels) e.g. 0.8f for bar width 1f * @param barSpace the space between individual bars in values (not pixels) e.g. 0.1f for bar width 1f */ public void groupBars(float fromX, float groupSpace, float barSpace) { if (getBarData() == null) { throw new RuntimeException("You need to set data for the chart before grouping bars."); } else { getBarData().groupBars(fromX, groupSpace, barSpace); notifyDataSetChanged(); } } }
/** * Groups all BarDataSet objects this data object holds together by modifying the x-value of their entries. * Previously set x-values of entries will be overwritten. Leaves space between bars and groups as specified * by the parameters. * Calls notifyDataSetChanged() afterwards. * * @param fromX the starting point on the x-axis where the grouping should begin * @param groupSpace the space between groups of bars in values (not pixels) e.g. 0.8f for bar width 1f * @param barSpace the space between individual bars in values (not pixels) e.g. 0.1f for bar width 1f */ public void groupBars(float fromX, float groupSpace, float barSpace) { if (getBarData() == null) { throw new RuntimeException("You need to set data for the chart before grouping bars."); } else { getBarData().groupBars(fromX, groupSpace, barSpace); notifyDataSetChanged(); } } }
/** * Groups all BarDataSet objects this data object holds together by modifying the x-value of their entries. * Previously set x-values of entries will be overwritten. Leaves space between bars and groups as specified * by the parameters. * Calls notifyDataSetChanged() afterwards. * * @param fromX the starting point on the x-axis where the grouping should begin * @param groupSpace the space between groups of bars in values (not pixels) e.g. 0.8f for bar width 1f * @param barSpace the space between individual bars in values (not pixels) e.g. 0.1f for bar width 1f */ public void groupBars(float fromX, float groupSpace, float barSpace) { if (getBarData() == null) { throw new RuntimeException("You need to set data for the chart before grouping bars."); } else { getBarData().groupBars(fromX, groupSpace, barSpace); notifyDataSetChanged(); } } }
public void addEntry(int dataSetIndex, double value) { histogramData.addEntry(barChart.getBarData(), dataSetIndex, value); recalculateXAxis(); }
public void clearData() { histogramData.clear(); for (IBarDataSet dataSet : barChart.getBarData().getDataSets()) { dataSet.clear(); } barChart.getBarData().notifyDataChanged(); barChart.invalidate(); }
public void setLabel(int dataSetIndex, String label) { barChart.getBarData().getDataSetByIndex(dataSetIndex).setLabel(label); barChart.getLegendRenderer().computeLegend(barChart.getBarData()); barChart.invalidate(); }
@Override public void onValueSelected(Entry e, Highlight h) { //得到包含此柱状图的 数据集 BarDataSet dataSets = (BarDataSet) barChart.getBarData().getDataSetForEntry(e); dataSet1TextView.setText("被点击的柱状图名称:\n" + dataSets.getLabel() + "X轴:" + (int) e.getX() + " Y轴" + e.getX()); StringBuffer allBarChart = new StringBuffer(); allBarChart.append("所有柱状图:\n"); for (IBarDataSet dataSet : barChart.getBarData().getDataSets()) { BarEntry entry = dataSet.getEntryForIndex((int) e.getX()); allBarChart.append(dataSet.getLabel()) .append("X轴:") .append((int) entry.getX()) .append(" Y轴") .append(entry.getY()) .append("\n"); } dataSet2TextView.setText(allBarChart.toString()); }
barChart.getBarData().setBarWidth(barWidth); barChart.getXAxis().setAxisMinimum(xAxisValue.get(0)); barChart.getXAxis().setAxisMaximum(barChart.getBarData().getGroupWidth(groupSpace, barSpace) * xAxisValue.size() + xAxisValue.get(0)); barChart.groupBars(xAxisValue.get(0), groupSpace, barSpace);
mChart.getBarData().setBarWidth(barWidth); mChart.getXAxis().setAxisMinimum(startYear); mChart.getXAxis().setAxisMaximum(mChart.getBarData().getGroupWidth(groupSpace, barSpace) * mSeekBarX.getProgress() + startYear); mChart.groupBars(startYear, groupSpace, barSpace); mChart.invalidate();
barChart.getBarData().setBarWidth(barWidth); barChart.getXAxis().setAxisMinimum(xAxisValue.get(0)); barChart.getXAxis().setAxisMaximum(barChart.getBarData().getGroupWidth(groupSpace, barSpace) * xAxisValue.size() + xAxisValue.get(0)); barChart.groupBars(xAxisValue.get(0), groupSpace, barSpace);
@Override public void onGetHistoryRecentTicketListSuccess(List<TicketOpenData> list) { bcAvgAnalysis = BarChartHelper.getBarChartHelper().generateBarChartConfig(bcAvgAnalysis); BarData barData; if (bcAvgAnalysis.getData() != null && bcAvgAnalysis.getData().getDataSetCount() > 0) { barData = bcAvgAnalysis.getBarData(); for (int i = 0; i < barData.getDataSetCount(); i++) { BarDataSet barDataSet = (BarDataSet) barData.getDataSetByIndex(i); barDataSet.setValues(generateEntry(list)); } bcAvgAnalysis.getData().notifyDataChanged(); bcAvgAnalysis.notifyDataSetChanged(); } else { List<Integer> colorList = new ArrayList<>(); colorList.add(getResources().getColor(R.color.main_red_color)); colorList.add(getResources().getColor(R.color.main_blue_color_4c65ed)); IBarDataSet barDataSet = BarChartHelper.getBarChartHelper().generateBarDataSet(generateEntry(list), new String[]{"普通码", "特别码"}, colorList); barData = new BarData(barDataSet); bcAvgAnalysis.setData(barData); bcAvgAnalysis.getXAxis().setValueFormatter((value, axis) -> (int) value + "号"); bcAvgAnalysis.setMarker(new DataMarkView(this, (e, highlight) -> ((int) e.getX()) + "号:" + e.getY() + "次")); } bcAvgAnalysis.animateY(3000); }
if (bcAvgAnalysis.getData() != null && bcAvgAnalysis.getData().getDataSetCount() > 0) { barData = bcAvgAnalysis.getBarData(); for (int i = 0; i < barData.getDataSetCount(); i++) { BarDataSet barDataSet = (BarDataSet) barData.getDataSetByIndex(i);