考慮到這隻適用於PieChart
,我想我可以說這是AChartEngine中的一個錯誤。直到它可以是固定的,例如時間,我發現了以下解決方法:
public class CustomPieChart extends org.achartengine.chart.PieChart {
private static final long serialVersionUID = 1L;
public CustomPieChart(CategorySeries dataset, DefaultRenderer renderer) {
super(dataset, renderer);
}
@Override
protected void drawLabel(Canvas canvas, String labelText, DefaultRenderer renderer, List<RectF> prevLabelsBounds, int centerX, int centerY, float shortRadius, float longRadius, float currentAngle, float angle, int left, int right, int color, Paint paint, boolean line, boolean display) {
paint.setTypeface(...typeface...);
super.drawLabel(canvas, labelText, renderer, prevLabelsBounds, centerX, centerY, shortRadius, longRadius, currentAngle, angle, left, right, color, paint, line, display);
}
@Override
protected int drawLegend(Canvas canvas, DefaultRenderer renderer, String[] titles, int left, int right, int y, int width, int height, int legendSize, Paint paint, boolean calculate) {
paint.setTypeface(...typeface...);
return super.drawLegend(canvas, renderer, titles, left, right, y, width, height, legendSize, paint, calculate);
}
@Override
public void drawTitle(Canvas canvas, int x, int y, int width, Paint paint) {
paint.setTypeface(...typeface...);
super.drawTitle(canvas, x, y, width, paint);
}
}
然後,代替使用ChartFactory
,手動實例化這樣的:
view = new GraphicalView(context, new CustomPieChart(dataset, renderer));
什麼是偉大的方式,感謝 –