use of com.github.mikephil.charting.data.BarEntry in project android-client by GenesisVision.
the class ProfitChartView method setChart.
public void setChart(List<Chart> charts) {
if (charts.isEmpty()) {
chart.clear();
return;
}
List<Entry> lineEntries = new ArrayList<>();
// List<BarEntry> barEntries = new ArrayList<>();
float index = 0;
for (Chart chart : charts) {
lineEntries.add(new Entry(index, chart.getTotalProfit().floatValue()));
// barEntries.add(new BarEntry(index, new float[]{
// chart.getManagerFund().floatValue() + chart.getInvestorFund().floatValue(),
// chart.getLoss().floatValue(),
// chart.getProfit().floatValue()}));
index++;
}
CombinedData data = new CombinedData();
data.setData(getLineData(lineEntries));
// data.setData(getBarData(barEntries));
chart.setData(data);
}
use of com.github.mikephil.charting.data.BarEntry in project MPAndroidChart by PhilJay.
the class ListViewMultiChartActivity method generateDataBar.
/**
* generates a random ChartData object with just one DataSet
*
* @return Bar data
*/
private BarData generateDataBar(int cnt) {
ArrayList<BarEntry> entries = new ArrayList<>();
for (int i = 0; i < 12; i++) {
entries.add(new BarEntry(i, (int) (Math.random() * 70) + 30));
}
BarDataSet d = new BarDataSet(entries, "New DataSet " + cnt);
d.setColors(ColorTemplate.VORDIPLOM_COLORS);
d.setHighLightAlpha(255);
BarData cd = new BarData(d);
cd.setBarWidth(0.9f);
return cd;
}
use of com.github.mikephil.charting.data.BarEntry in project MPAndroidChart by PhilJay.
the class SimpleFragment method generateBarData.
protected BarData generateBarData(int dataSets, float range, int count) {
ArrayList<IBarDataSet> sets = new ArrayList<>();
for (int i = 0; i < dataSets; i++) {
ArrayList<BarEntry> entries = new ArrayList<>();
for (int j = 0; j < count; j++) {
entries.add(new BarEntry(j, (float) (Math.random() * range) + range / 4));
}
BarDataSet ds = new BarDataSet(entries, getLabel(i));
ds.setColors(ColorTemplate.VORDIPLOM_COLORS);
sets.add(ds);
}
BarData d = new BarData(sets);
d.setValueTypeface(tf);
return d;
}
use of com.github.mikephil.charting.data.BarEntry in project MPAndroidChart by PhilJay.
the class StackedBarActivityNegative method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.activity_age_distribution);
setTitle("StackedBarActivityNegative");
chart = findViewById(R.id.chart1);
chart.setOnChartValueSelectedListener(this);
chart.setDrawGridBackground(false);
chart.getDescription().setEnabled(false);
// scaling can now only be done on x- and y-axis separately
chart.setPinchZoom(false);
chart.setDrawBarShadow(false);
chart.setDrawValueAboveBar(true);
chart.setHighlightFullBarEnabled(false);
chart.getAxisLeft().setEnabled(false);
chart.getAxisRight().setAxisMaximum(25f);
chart.getAxisRight().setAxisMinimum(-25f);
chart.getAxisRight().setDrawGridLines(false);
chart.getAxisRight().setDrawZeroLine(true);
chart.getAxisRight().setLabelCount(7, false);
chart.getAxisRight().setValueFormatter(new CustomFormatter());
chart.getAxisRight().setTextSize(9f);
XAxis xAxis = chart.getXAxis();
xAxis.setPosition(XAxisPosition.BOTH_SIDED);
xAxis.setDrawGridLines(false);
xAxis.setDrawAxisLine(false);
xAxis.setTextSize(9f);
xAxis.setAxisMinimum(0f);
xAxis.setAxisMaximum(110f);
xAxis.setCenterAxisLabels(true);
xAxis.setLabelCount(12);
xAxis.setGranularity(10f);
xAxis.setValueFormatter(new IAxisValueFormatter() {
private final DecimalFormat format = new DecimalFormat("###");
@Override
public String getFormattedValue(float value, AxisBase axis) {
return format.format(value) + "-" + format.format(value + 10);
}
});
Legend l = chart.getLegend();
l.setVerticalAlignment(Legend.LegendVerticalAlignment.BOTTOM);
l.setHorizontalAlignment(Legend.LegendHorizontalAlignment.RIGHT);
l.setOrientation(Legend.LegendOrientation.HORIZONTAL);
l.setDrawInside(false);
l.setFormSize(8f);
l.setFormToTextSpace(4f);
l.setXEntrySpace(6f);
// IMPORTANT: When using negative values in stacked bars, always make sure the negative values are in the array first
ArrayList<BarEntry> values = new ArrayList<>();
values.add(new BarEntry(5, new float[] { -10, 10 }));
values.add(new BarEntry(15, new float[] { -12, 13 }));
values.add(new BarEntry(25, new float[] { -15, 15 }));
values.add(new BarEntry(35, new float[] { -17, 17 }));
values.add(new BarEntry(45, new float[] { -19, 20 }));
values.add(new BarEntry(45, new float[] { -19, 20 }, getResources().getDrawable(R.drawable.star)));
values.add(new BarEntry(55, new float[] { -19, 19 }));
values.add(new BarEntry(65, new float[] { -16, 16 }));
values.add(new BarEntry(75, new float[] { -13, 14 }));
values.add(new BarEntry(85, new float[] { -10, 11 }));
values.add(new BarEntry(95, new float[] { -5, 6 }));
values.add(new BarEntry(105, new float[] { -1, 2 }));
BarDataSet set = new BarDataSet(values, "Age Distribution");
set.setDrawIcons(false);
set.setValueFormatter(new CustomFormatter());
set.setValueTextSize(7f);
set.setAxisDependency(YAxis.AxisDependency.RIGHT);
set.setColors(Color.rgb(67, 67, 72), Color.rgb(124, 181, 236));
set.setStackLabels(new String[] { "Men", "Women" });
BarData data = new BarData(set);
data.setBarWidth(8.5f);
chart.setData(data);
chart.invalidate();
}
use of com.github.mikephil.charting.data.BarEntry in project MPAndroidChart by PhilJay.
the class HorizontalBarBuffer method feed.
@Override
public void feed(IBarDataSet data) {
float size = data.getEntryCount() * phaseX;
float barWidthHalf = mBarWidth / 2f;
for (int i = 0; i < size; i++) {
BarEntry e = data.getEntryForIndex(i);
if (e == null)
continue;
float x = e.getX();
float y = e.getY();
float[] vals = e.getYVals();
if (!mContainsStacks || vals == null) {
float bottom = x - barWidthHalf;
float top = x + barWidthHalf;
float left, right;
if (mInverted) {
left = y >= 0 ? y : 0;
right = y <= 0 ? y : 0;
} else {
right = y >= 0 ? y : 0;
left = y <= 0 ? y : 0;
}
// multiply the height of the rect with the phase
if (right > 0)
right *= phaseY;
else
left *= phaseY;
addBar(left, top, right, bottom);
} else {
float posY = 0f;
float negY = -e.getNegativeSum();
float yStart = 0f;
// fill the stack
for (int k = 0; k < vals.length; k++) {
float value = vals[k];
if (value >= 0f) {
y = posY;
yStart = posY + value;
posY = yStart;
} else {
y = negY;
yStart = negY + Math.abs(value);
negY += Math.abs(value);
}
float bottom = x - barWidthHalf;
float top = x + barWidthHalf;
float left, right;
if (mInverted) {
left = y >= yStart ? y : yStart;
right = y <= yStart ? y : yStart;
} else {
right = y >= yStart ? y : yStart;
left = y <= yStart ? y : yStart;
}
// multiply the height of the rect with the phase
right *= phaseY;
left *= phaseY;
addBar(left, top, right, bottom);
}
}
}
reset();
}
Aggregations