Android / Google Chart / ImageView – sample

This is an answer to one simple question: how to implement a Google Chart graph of an Android application?
well, first use the wizard offered to facilitate the creation of our graphics,go here:
select your graph type and modify it to suit your needs,then copy the http link is on the right of the page(example:×225&cht=v&chco=FF6342,ADDE63,63C6DE&chds=0,110&chd=t:100,80,60,30,30,30,10&chdl=A|B|C)
This will be the base url to create your chart based on data that you want to show.
I used a AsyncTask to load the graph, here’s the code:

private class LoadingRemoteGraph extends AsyncTask<String, Void, Bitmap> {
	private final WeakReference<ImageView> imageViewReference;
	ProgressDialog dialog = null;
	private Context context = null;
	private ImageView ivT;
	int vHeight=0;
	int vWidth = 0;

	public LoadingRemoteGraph(Context contextT, final ImageView imageView) {
		context = contextT;
		imageViewReference = new WeakReference<ImageView>(imageView);

	protected void onPreExecute() {
		dialog =, "",
				getString(R.string.str_generic_progressbar), true);

	protected Bitmap doInBackground(String...params) {
		Bitmap bmGraphT = null;
		URL img = null;
		ViewTreeObserver vto = ivT.getViewTreeObserver();
		vto.addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
			public void onGlobalLayout() {
				vHeight = ivT.getHeight();
				vWidth = ivT.getWidth();
		String url=params[0].replace("WIDTH_GRAPH", String.valueOf(vWidth));
		url=url.replace("HEIGHT_GRAPH", String.valueOf(vHeight));
		try {
			img = new URL(url);
		} catch (MalformedURLException e) {

		try {
			bmGraphT = BitmapFactory.decodeStream(img.openStream());
		} catch (IOException e) {

		return bmGraphT;

	protected void onPostExecute(Bitmap bmT) {

		if (isCancelled()) {
			bmT = null;
		if (imageViewReference != null) {
			ImageView imageView = imageViewReference.get();
			if (imageView != null) {



you can use this task in the onResume method,like this:

public void onResume() {

	ImageView ivGraph = (ImageView) findViewById(;
	String strUrl = ",0,158&chxs=0,676767,11.5,0,_,676767&chxt=y&chbh=a&chs="
			+ "x"
			+ "&cht=bvg&chco=0000FF,FF0000&chds=0,158,0,158&chd=t:"
			+ 79
			+ "|" + 30 + "&chdl=Tuo|Media&chdlp=b";

	LoadingRemoteGraph task = new LoadingRemoteGraph(ActivityTest.this,

that’s all.8y3


2 pensieri su “Android / Google Chart / ImageView – sample

    1. If you want to know how to replace the values ​​in the graph, the answer is that you should study the URL chart :p
      after that you should change the URL of the graph as I did in the example to define the height and width;usually the dataset (values ​​which appear in the graph) is found on the part of the URL that begin with chd=t: ,each value of the dataset is divided from the others by a comma (,) and each data set is divided from other datasets through a pipe (|), is very simple … hope that help.8y3


Inserisci i tuoi dati qui sotto o clicca su un'icona per effettuare l'accesso:


Stai commentando usando il tuo account Chiudi sessione / Modifica )

Foto Twitter

Stai commentando usando il tuo account Twitter. Chiudi sessione / Modifica )

Foto di Facebook

Stai commentando usando il tuo account Facebook. Chiudi sessione / Modifica )

Google+ photo

Stai commentando usando il tuo account Google+. Chiudi sessione / Modifica )

Connessione a %s...