我的图表使用achartengine有问题。我从我的sqlite数据库中设置数据集的数据,我可以在图表上成功显示它,但条形宽度是缩小的。这是我的GenerateEngine
类,用于从sqlite db生成条。
public class GenerateChart {
private ExpensesDataSource datasource;
private SpinnerValues spinnerValues = new SpinnerValues();
private SimpleDateFormat monthFormat, yearFormat;
String month, year;
List<String> values;
XYSeries series;
public XYMultipleSeriesDataset getExpensesBarDataset(Context context) {
datasource = new ExpensesDataSource(context);
monthFormat = new SimpleDateFormat("MM");
month = monthFormat.format(new Date());
yearFormat = new SimpleDateFormat("yyyy");
year = yearFormat.format(new Date());
datasource.openToRead();
values = datasource.GetTotalEachCategory(month, year);
datasource.close();
XYMultipleSeriesDataset dataset = new XYMultipleSeriesDataset();
XYSeries series;
for(int i = 0; i < spinnerValues.categoryText.length; i++) {
series = new XYSeries(spinnerValues.categoryText[i]);
series.add(i, Double.parseDouble(values.get(i)));
dataset.addSeries(series);
}
return dataset;
}
public XYMultipleSeriesRenderer getExpensesBarRenderer() {
XYMultipleSeriesRenderer renderer = new XYMultipleSeriesRenderer();
renderer.setAxisTitleTextSize(16);
renderer.setChartTitleTextSize(20);
renderer.setLabelsTextSize(15);
renderer.setLegendTextSize(15);
renderer.setMargins(new int[] { 30, 40, 15, 0 });
XYSeriesRenderer r;
for(int i = 0; i < spinnerValues.categoryColor.length; i++) {
r = new XYSeriesRenderer();
r.setColor(Color.parseColor(spinnerValues.categoryColor[i]));
r.setLineWidth(20);
r.setFillPoints(true);
r.setDisplayChartValues(true);
renderer.addSeriesRenderer(r);
}
return renderer;
}
public void myChartSettings(XYMultipleSeriesRenderer renderer, String month, String year) {
renderer.setChartTitle("Pratinjau Grafik Pengeluaran Bulan " + month + " Tahun " + year);
renderer.setXAxisMin(-10);
renderer.setXAxisMax(10);
renderer.setYAxisMin(0);
renderer.setYAxisMax(500000);
renderer.setYLabelsAlign(Paint.Align.RIGHT);
renderer.setBarSpacing(.1);
renderer.setXTitle("Kategori");
renderer.setYTitle("Total Pengeluaran");
renderer.setShowGrid(true);
renderer.setGridColor(Color.GRAY);
renderer.setZoomButtonsVisible(true);
renderer.setXLabels(0); // sets the number of integer labels to appear
}}
这是我从班上得到的。
我想添加条的宽度以便它正确。我将不胜感激,谢谢。
答案 0 :(得分:1)
setBarWidth api用于 XYMultipleSeriesRenderer 请参阅此Api - &gt; API
所以在你的代码中你需要改变这个:
Inside getExpensesBarRenderer() Api
renderer.setBarWidth()