我试图在aChartengine中设置圆环图内圆半径和外圆半径,下面是我的代码:
public class MainActivity extends Activity {
GraphicalView gv;
RelativeLayout rl;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
List<double[]> values1 = new ArrayList<double[]>();
values1.add(new double[] { 15, 5 });
gv = createIntent(values1);
rl = (RelativeLayout) findViewById(R.id.rel);
rl.addView(gv);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
public GraphicalView createIntent(List<double[]> values1) {
List<String[]> titles = new ArrayList<String[]>();
titles.add(new String[] { " ", " " });
int[] colors = new int[] { Color.BLUE, Color.GREEN };
DefaultRenderer renderer = buildCategoryRenderer(colors);
renderer.setApplyBackgroundColor(true);
renderer.setShowLegend(false);
renderer.setShowLabels(false);
renderer.setStartAngle(270);
renderer.setBackgroundColor(Color.rgb(222, 222, 200));
renderer.setLabelsColor(Color.GRAY);
return ChartFactory.getDoughnutChartView(MainActivity.this,
buildMultipleCategoryDataset("Project budget", titles, values1),
renderer);
}
protected MultipleCategorySeries buildMultipleCategoryDataset(String title,
List<String[]> titles, List<double[]> values) {
MultipleCategorySeries series = new MultipleCategorySeries(title);
int k = 0;
for (double[] value : values) {
series.add(2007 + k + "", titles.get(k), value);
k++;
}
return series;
}
protected DefaultRenderer buildCategoryRenderer(int[] colors) {
DefaultRenderer renderer = new DefaultRenderer();
renderer.setLabelsTextSize(15);
renderer.setLegendTextSize(15);
renderer.setMargins(new int[] { 20, 30, 15, 0 });
for (int color : colors) {
SimpleSeriesRenderer r = new SimpleSeriesRenderer();
r.setColor(color);
renderer.addSeriesRenderer(r);
}
return renderer;
}
但我有浏览器这个设置半径的查询,在很多搜索中我在画布上找到了半径,但在我的情况下我没有画布。
有谁能告诉我如何在我的代码中设置半径?
答案 0 :(得分:2)
renderer.setScale((flaot)1.3)解决了我的问题,但内半径和外半径大约不完美。
答案 1 :(得分:1)
你只需要去掉decCoef的值(DoughnutChart类中的变量)。 在DefaultRenderer中添加自己的radius变量并创建getter和setter。 现在,在DoughnutChart中使用此变量。
例如,
DefaultRenderer defaultRenderer = new DefaultRenderer();
defaultRenderer.setmWidth(0.1f);
在DoughnutChart课程中:
public class DoughnutChart extends RoundChart {
private float mWidth; // make your own variable and initialize in constructor
public DoughnutChart(MultipleCategorySeries dataset, DefaultRenderer renderer) {
super(null, renderer);
mDataset = dataset;
mWidth = renderer.getmWidth();
}
double decCoef = mWidth / cLength; // change value of decCoef by using our variable.