Reputation: 2056
I'm trying to make some graphics in my application with the AchartEngine API
but it doesn't works.
Can anyone explain me how to have a view with a graphic
instead of Intent
?
Cause in the demo code it's only by Intent
, not by view.
edit: I tried to test the 2 options at the same time: I have a linearLayout with a button in it:
<LinearLayout android:id="@+id/list_infos_layout_stat" android:orientation="horizontal" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_weight="1" >
<Button
android:id="@+id/list_infos_bouton_stats"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="statistiques"
/>
When I hit the button, a new activity is made by the ChartFactory.getLineChartIntent(..)
method and it works great.
And in the same LinearLayout, I put a view returned by ChartFactory.getLineChartView
method, its ok I have the graphic at the right of the button.
But when I remove the button I have nothing...
View graphique = new ReponsesChart().getView(contexte);
if (graphique !=null){
LinearLayout layout = (LinearLayout)convertView.findViewById(R.id.list_infos_layout_stat);
layout.addView(graphique, new LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.FILL_PARENT));
} else {
Log.d("Infos", "GRAPHIQUE NULL");
}
edit 2: Fixed by replacing Fill Parent properties when I add the view to the layout by the width of the screen
Upvotes: 2
Views: 3734
Reputation: 887
In the ChartFactory class there are several methods that you can use like this:
GraphicalView gView=ChartFactory.getDoughnutChartView(context,data,renderer);
and similar ones for other graph types like line charts and bar charts. You can then simply call:
setContentView(gView);
Download the documentation for AChartEngine, its pretty easy to find there.
Upvotes: 3
Reputation: 2618
Would something that writes to a bitmap help? I use the following in some of my code:
final XYMultipleSeriesRenderer multipleRenderer = new XYMultipleSeriesRenderer();
final XYSeriesRenderer renderer = new XYSeriesRenderer();
multipleRenderer.addSeriesRenderer(renderer);
final XYMultipleSeriesDataset dataset = final XYMultipleSeriesDataset dataset = ...
final Bitmap image1 = Bitmap.createBitmap(WIDTH, HEIGHT, Bitmap.Config.ARGB_8888);
final TimeChart tc = new TimeChart(dataset, multipleRenderer);
final Canvas canvas = new Canvas(image1);
tc.draw(canvas, 0, 0, WIDTH, HEIGHT, paint);
final Bitmap image = Bitmap.createBitmap(image1, 0, 0, WIDTH, HEIGHT);
Note that I've cut out a lot of code relating to initialising the multipleRender and dataset
Upvotes: 0