java - How to display bar labels in HorizontalBarChart? -
i have horizontalbarchart mpandroidchart library (version v3.0.0-beta1) in display monthly spending of user's accounts.
so implemented method:
list<account> accounts = getaccounts(); final arraylist<barentry> entries = new arraylist<>(); float count = 0f; (account account : accounts) { entries.add(new barentry(count++, new float[]{float.valueof(account.getbalance())}, account.getname())); } bardataset dataset = new bardataset(entries, " "); dataset.setcolors(colortemplate.pastel_colors); dataset.setvaluetextsize(10f); bardata data = new bardata(dataset); horizontalbarchartmonthlyspending.setdata(data); horizontalbarchartmonthlyspending.setdescription("gastos por conta neste mês!"); horizontalbarchartmonthlyspending.getaxisleft().setdrawlabels(false); horizontalbarchartmonthlyspending.getaxisright().setdrawlabels(false); horizontalbarchartmonthlyspending.setfitbars(true); horizontalbarchartmonthlyspending.settouchenabled(false);
and got:
what want is, beside every bar, put description of related account. tried in line 6 account.getname()
didn't appear anywhere in report.
is there way it?
i had problem , correct putting code:
horizontalbarchartmonthlyspending.getxaxis().setvalueformatter(new axisvalueformatter() { @override public string getformattedvalue(float value, axisbase axis) { return entries.get((int) value).getdata().tostring(); } @override public int getdecimaldigits() { return 0; } }); xaxis xaxis = horizontalbarchartmonthlyspending.getxaxis(); xaxis.setgranularity(1f); xaxis.setgranularityenabled(true);
Comments
Post a Comment