@Override public void onValueSelected(Entry e, Highlight h) { if (e == null) return; RectF bounds = mOnValueSelectedRectF; chart.getBarBounds((BarEntry) e, bounds); MPPointF position = chart.getPosition(e, chart.getData().getDataSetByIndex(h.getDataSetIndex()) .getAxisDependency()); Log.i("bounds", bounds.toString()); Log.i("position", position.toString()); MPPointF.recycleInstance(position); }
private void setData(int count, float range) { float barWidth = 9f; float spaceForBar = 10f; ArrayList<BarEntry> values = new ArrayList<>(); for (int i = 0; i < count; i++) { float val = (float) (Math.random() * range); values.add(new BarEntry(i * spaceForBar, val, getResources().getDrawable(R.drawable.star))); } BarDataSet set1; if (chart.getData() != null && chart.getData().getDataSetCount() > 0) { set1 = (BarDataSet) chart.getData().getDataSetByIndex(0); set1.setValues(values); chart.getData().notifyDataChanged(); chart.notifyDataSetChanged(); } else { set1 = new BarDataSet(values, "DataSet 1"); set1.setDrawIcons(false); ArrayList<IBarDataSet> dataSets = new ArrayList<>(); dataSets.add(set1); BarData data = new BarData(dataSets); data.setValueTextSize(10f); data.setValueTypeface(tfLight); data.setBarWidth(barWidth); chart.setData(data); } }
List<IBarDataSet> sets = chart.getData() .getDataSets(); List<IBarDataSet> sets = chart.getData() .getDataSets(); if(chart.getData() != null) { chart.getData().setHighlightEnabled(!chart.getData().isHighlightEnabled()); chart.invalidate(); for (IBarDataSet set : chart.getData().getDataSets()) ((BarDataSet)set).setBarBorderWidth(set.getBarBorderWidth() == 1.f ? 0.f : 1.f);
List<IBarDataSet> sets = chart.getData() .getDataSets(); List<IBarDataSet> sets = chart.getData() .getDataSets(); if(chart.getData() != null) { chart.getData().setHighlightEnabled(!chart.getData().isHighlightEnabled()); chart.invalidate(); for (IBarDataSet set : chart.getData().getDataSets()) ((BarDataSet)set).setBarBorderWidth(set.getBarBorderWidth() == 1.f ? 0.f : 1.f);
@SuppressLint("NewApi") @Override public void onValueSelected(Entry e, Highlight h) { if (e == null) return; RectF bounds = mOnValueSelectedRectF; mChart.getBarBounds((BarEntry) e, bounds); MPPointF position = mChart.getPosition(e, mChart.getData().getDataSetByIndex(h.getDataSetIndex()) .getAxisDependency()); Log.i("bounds", bounds.toString()); Log.i("position", position.toString()); MPPointF.recycleInstance(position); }
private void setData(int count, float range) { float barWidth = 9f; float spaceForBar = 10f; ArrayList<BarEntry> yVals1 = new ArrayList<BarEntry>(); for (int i = 0; i < count; i++) { float val = (float) (Math.random() * range); yVals1.add(new BarEntry(i * spaceForBar, val)); } BarDataSet set1; if (mChart.getData() != null && mChart.getData().getDataSetCount() > 0) { set1 = (BarDataSet)mChart.getData().getDataSetByIndex(0); set1.setValues(yVals1); mChart.getData().notifyDataChanged(); mChart.notifyDataSetChanged(); } else { set1 = new BarDataSet(yVals1, "DataSet 1"); ArrayList<IBarDataSet> dataSets = new ArrayList<IBarDataSet>(); dataSets.add(set1); BarData data = new BarData(dataSets); data.setValueTextSize(10f); data.setValueTypeface(mTfLight); data.setBarWidth(barWidth); mChart.setData(data); } }
switch (item.getItemId()) { case R.id.actionToggleValues: { List<IBarDataSet> sets = mChart.getData() .getDataSets(); if(mChart.getData() != null) { mChart.getData().setHighlightEnabled(!mChart.getData().isHighlightEnabled()); mChart.invalidate(); for (IBarDataSet set : mChart.getData().getDataSets()) ((BarDataSet)set).setBarBorderWidth(set.getBarBorderWidth() == 1.f ? 0.f : 1.f);
switch (item.getItemId()) { case R.id.actionToggleValues: { List<IBarDataSet> sets = mChart.getData() .getDataSets(); if(mChart.getData() != null) { mChart.getData().setHighlightEnabled(!mChart.getData().isHighlightEnabled()); mChart.invalidate(); for (IBarDataSet set : mChart.getData().getDataSets()) ((BarDataSet)set).setBarBorderWidth(set.getBarBorderWidth() == 1.f ? 0.f : 1.f);