0

DefaultRenderer.setTextTypeface(Typeface) doesn't seem to work, is this a known problem? I use the very same typeface everywhere in my app, so it's 100% all right. But if I pass it to the renderer, nothing changes. Using the other setTextTypeface(), which accepts standard system fonts, seems to be inoperative as well.

Some source code, although it's more than straightforward:

DefaultRenderer renderer = new DefaultRenderer();
renderer.setAntialiasing(true);
renderer.setChartTitle(title);
...
renderer.setTextTypeface(MyApplication.getInstance().font.condensedNormal);
renderer.setShowLabels(true);
...

No error, no message, just the font doesn't get changed, I receive the system font all right.

Version 1.1.0, the latest that I could find.

Addendum: after some testing, it's only the PieChart that has the problem. Others seem to accept the font all right.

4

2 回答 2

2

achartengine-1.1.0.jar这是在添加 中更新的新功能Change text font by setting a Typeface object

添加了新方法

public void setTextTypeface(android.graphics.Typeface typeface)
// Sets the text typeface.

Parameters:
typeface - the typeface

所以请更新您的图书馆并遵循代码 -

Typeface myNewFace = Typeface.createFromAsset(getAssets(), "abc.ttf");
renderer.setTextTypeface(myNewFace);

希望这对你有帮助..

于 2013-07-24T12:39:05.330 回答
2

考虑到这仅适用于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));
于 2013-07-24T12:20:08.390 回答