-1
私はMPチャートライブラリを使用しています。私の問題は、値がそれぞれのバーに設定されていないことです。 JSONから値を取得し、棒グラフのy値に入れます。 水平バーがテキスト値をそれぞれのバーに設定しない
番号1,2,3が設定されていません。ここで
はコードです:ここでは
mChart = (HorizontalBarChart) findViewById(R.id.chart1);
mChart.setOnChartValueSelectedListener(new OnChartValueSelectedListener() {
@Override
public void onValueSelected(Entry e, int dataSetIndex, Highlight h) {
if (e == null)
return;
RectF bounds = mChart.getBarBounds((BarEntry) e);
PointF position = mChart.getPosition(e, mChart.getData().getDataSetByIndex(dataSetIndex)
.getAxisDependency());
Log.i("bounds", bounds.toString());
Log.i("position", position.toString());
}
@Override
public void onNothingSelected() {
}
});
mChart.setDrawBarShadow(false);
mChart.setDrawValueAboveBar(true);
mChart.setDescription("");
mChart.setMaxVisibleValueCount(5);
mChart.setPinchZoom(false);
mChart.setDrawGridBackground(false);
XAxis xl = mChart.getXAxis();
xl.setPosition(XAxis.XAxisPosition.BOTTOM);
xl.setDrawAxisLine(false);
xl.setDrawGridLines(false);
xl.setGridLineWidth(0.3f);
YAxis yl = mChart.getAxisLeft();
yl.setDrawAxisLine(false);
yl.setDrawGridLines(false);
yl.setGridLineWidth(0.3f);
YAxis yr = mChart.getAxisRight();
yr.setDrawAxisLine(false);
yr.setDrawGridLines(false);
mChart.animateY(2500);
mChart.getAxisLeft().setDrawLabels(false);
mChart.getAxisRight().setDrawLabels(false);
mChart.getXAxis().setDrawLabels(true);
mChart.getLegend().setEnabled(false);
mChart.getXAxis().setTextColor(Color.parseColor("#585858"));
try {
ArrayList<String> xVals = new ArrayList<String>();
ArrayList<BarEntry> yVals1 = new ArrayList<BarEntry>();
JSONObject jsonObject = new JSONObject(response);
boolean status = jsonObject.getBoolean("status");
JSONObject jsnObj_rating_cunt = jsonObject.getJSONObject("rating_count");
int one = jsnObj_rating_cunt.getInt("1");
int two = jsnObj_rating_cunt.getInt("2");
int three = jsnObj_rating_cunt.getInt("3");
int four = jsnObj_rating_cunt.getInt("4");
int five = jsnObj_rating_cunt.getInt("5");
xVals.add(0, "1 Star");
xVals.add(1, "2 Star");
xVals.add(2, "3 Star");
xVals.add(3, "4 Star");
xVals.add(4, "5 Star");
yVals1.add(new BarEntry((float) one, 0));
yVals1.add(new BarEntry((float) two, 1));
yVals1.add(new BarEntry((float) three, 2));
yVals1.add(new BarEntry((float) four, 3));
yVals1.add(new BarEntry((float) five, 4));
BarDataSet set1 = new BarDataSet(yVals1, "");
ArrayList<IBarDataSet> dataSets = new ArrayList<IBarDataSet>();
set1.setColors(REVIEWS_COLORS);
dataSets.add(set1);
BarData data = new BarData(xVals, dataSets);
data.setValueTextSize(10f);
mChart.setData(data);
グラフが来ていると値が来るが、それはバーに設定されていないにもあるデータをフェッチするためにJSONです。
ありがとうございます。
1,2,3人が手動で設定していますか、ライブラリが組み込まれています –
値が表示されないことを示すためにマークします。 json – Shane
から来る星の値は、この文を印刷できますか?この後、Log.e( "sizeOfDataset"、 "+ dataSets.size())、dataSets.add(set1); –