i have filled all required data into dataset of graph(with x-axis values and y-axis values).
but on first time rendering chart it will not display.after click or touch on chart area it will display.
provide code


/**
* initialize pie chart
*/
private void initPieChart() {
Log.e(TAG, "Init Pie Chart");
mPieChartPortfolio.setDescription("");
mPieChartPortfolio.setNoDataText("No chart data avaiable");
mPieChartPortfolio
.setNoDataTextDescription("You need to provide data for the chart.");
mPieChartPortfolio.setHighlightEnabled(true);
mPieChartPortfolio.setTouchEnabled(true);
mPieChartPortfolio.setDrawHoleEnabled(true);
mPieChartPortfolio.setHoleColorTransparent(true);
mPieChartPortfolio.setTransparentCircleRadius(Color.WHITE);
mPieChartPortfolio.setHoleRadius(0f);
mPieChartPortfolio.setTransparentCircleRadius(0f);
mPieChartPortfolio.setRotationAngle(360 - 135f);
mPieChartPortfolio.setRotationEnabled(false);
mPieChartPortfolio.setHorizontalScrollBarEnabled(true);
Log.i("asset_length", arrAssetName.length + "");
setChartData(arrAssetName.length, 100);
Legend legend = mPieChartPortfolio.getLegend();
legend.setEnabled(false);
}
private void setChartData(int count, int range) {
Log.e(TAG, "Set Data");
// temporary data
arrValue = new float[] { perGold, perSilver, perPlatinum, perPalladium };
// y value
ArrayList<Entry> yValues = new ArrayList<Entry>();
for (int i = 0; i < count; i++) {
yValues.add(new Entry((float) (arrValue[i]), i));
}
// x value
xValues = new ArrayList<String>();
for (int i = 0; i < count; i++) {
String str = arrValue[i] + "";
if (str.toString().equals("0.0")) {
arrAssetName[i] = "";
}
xValues.add(arrAssetName[i]);
}
PieDataSet dataSet = new PieDataSet(yValues, "Assets");
dataSet.setSliceSpace(0f);
dataSet.setSelectionShift(5f);
// set colors
ArrayList<Integer> colors = new ArrayList<Integer>();
for (int c : ColorTemplate.createColors(new int[] { COLOR_GOLD,
COLOR_SILVER, COLOR_PLATINUM, COLOR_PALLADIUM }))
colors.add(c);
colors.add(ColorTemplate.getHoloBlue());
dataSet.setColors(colors);
mPieDataPortfolio = new PieData(xValues, dataSet);
mPieDataPortfolio.setValueFormatter(new PercentFormatter());
mPieDataPortfolio.setValueTextSize(12f);
mPieDataPortfolio.setValueTextColor(contextAct.getResources().getColor(
R.color.white));
mPieChartPortfolio.setData(mPieDataPortfolio);
mPieChartPortfolio.setHighlightEnabled(true);
Log.i("pie chart set===>", "pie chart set===>");
}
call invalidate() after all setup
after called invalidate() its worked.
thanks
I need to show data on click of particular portion on the pie chart..like a label..how to do it ?
Hii
Override onNothingSelected() and onValueSelected method.
public void onNothingSelected() {
Log.i("PieChart", "nothing selected");
try {
dataSet.getColors().set(intSelectedPos, Color.rgb(3, 3, 3));
} catch (Exception e) {
e.printStackTrace();
}
}
public void onValueSelected(Entry e, Highlight h) {
if (e == null)
return;
intSelectedPos = (int) h.getX();
if (intSelectedPos >= 0) {
for (int i = 0; i < dataSet.getColors().size(); i++) {
dataSet.getColors().set(i, Color.rgb(3, 3, 3));
}
if (intSelectedPos == (int) h.getX()) {
dataSet.getColors().set(intSelectedPos, Color.rgb(1, 229, 68));
}
}
Log.i("VAL SELECTED", "Value: " + e.getY() + ", index: " + h.getX() + ", DataSet index: " + h.getDataSetIndex());
}
call
invalidate()after all setup
Perfect !
If dataset is changing,call notifyDataSetChanged() will help before calling invalidsate()
Most helpful comment
call
invalidate()after all setup