Reputation: 157
I use achartengine to draw my chart in an android application and have 2 issues with bar chart.
1: values at top bar doesn't align center
2: width of bar too small when just 1 bar in chart
Here my code for setting chart
GraphicalView mChart;
// Creating an XYSeries for Income
XYSeries incomeSeries = new XYSeries("\n" + note);
// Adding data to Series
// Arraylist<String> althongtin include input data (some numbers character, eg: {125, 4356, 50000})
for(int i=0;i<althongtin.size();i++){
incomeSeries.add(i, Double.parseDouble(althongtin.get(i)));
}
// Creating a dataset to hold each series
XYMultipleSeriesDataset dataset = new XYMultipleSeriesDataset();
// Adding Income Series to the dataset
dataset.addSeries(incomeSeries);
XYSeriesRenderer incomeRenderer = new XYSeriesRenderer();
incomeRenderer.setColor(color);
incomeRenderer.setChartValuesTextSize(20);
incomeRenderer.setFillPoints(true);
incomeRenderer.setDisplayChartValues(true);
incomeRenderer.setChartValuesTextAlign(Paint.Align.CENTER);
XYMultipleSeriesRenderer multiRenderer = new XYMultipleSeriesRenderer();
multiRenderer.setXLabels(0);
multiRenderer.setChartTitle(ten);
multiRenderer.setXTitle(cotx);
multiRenderer.setYTitle(coty);
multiRenderer.setYLabelsAlign(Paint.Align.LEFT);
multiRenderer.setBarSpacing(1);
multiRenderer.setBarWidth(50);
multiRenderer.setYAxisMin(0);
multiRenderer.setYAxisMax(max + (max/10));
multiRenderer.setXAxisMin(-1);
multiRenderer.setXAxisMax(althongtin.size() + 1);
multiRenderer.setLabelsTextSize(15);
multiRenderer.setLegendTextSize(20);
multiRenderer.setAxisTitleTextSize(20);
multiRenderer.setChartTitleTextSize(20);
multiRenderer.setLabelsColor(Color.BLACK);
multiRenderer.setAxesColor(Color.BLACK);
multiRenderer.setApplyBackgroundColor(true);
multiRenderer.setBackgroundColor(Color.TRANSPARENT);
multiRenderer.setMarginsColor(Color.argb(0,255,255,255));
multiRenderer.setXLabelsColor(Color.BLACK);
multiRenderer.setYLabelsColor(0, Color.BLACK);
multiRenderer.addSeriesRenderer(incomeRenderer);
String[] types = new String[] {BarChart.TYPE};
mChart = (GraphicalView) ChartFactory.getCombinedXYChartView(getBaseContext(), dataset, multiRenderer, types);
multiRenderer.setClickEnabled(true);
multiRenderer.setSelectableBuffer(10);
chartLayout.addView(mChart);
Thanks.
Updated: the second issue is fixed by upgrade to achartengine 1.2.0. Thank yoou, Dan.
Upvotes: 4
Views: 959
Reputation: 32391
For the first issue, you may want to upgrade to the 1.2.0 nightly build.
For the second one, there is: renderer.setBarWidth(widthInPixels);
as this is the solutions to set the bar width when there is one single item in the series.
Upvotes: 1
Reputation: 3255
why not using ChartFactory.getBarChartView
instead of ChartFactory.getCombinedXYChartIntent
?
I think it will fix ur problem .
Upvotes: 0