package com.example.wordbook.chart;

import org.achartengine.ChartFactory;
import org.achartengine.GraphicalView;
import org.achartengine.renderer.DefaultRenderer;

import android.content.Context;

/**
 * A StatPieChart class.
 */
public class StatPieChart extends AbstractDemoChart {

	/** The series title. */
	private String title;
	/** The categories. */
	private String[] categories;
	/** The values. */
	private double[] values;
	/** The colors. */
	private int[] colors;

	/**
	 * Constructor for the StatPieChart class.
	 * 
	 * @param title
	 *            the series title
	 * @param categories
	 *            the categories
	 * @param values
	 *            the values
	 * @param colors
	 *            the colors
	 */
	public StatPieChart(String title, String[] categories, double[] values,
			int[] colors) {
		this.title = title;
		this.categories = categories.clone();
		this.values = values.clone();
		this.colors = colors.clone();
	}

	/**
	 * Executes the StatPieChart demo.
	 * 
	 * @param context
	 *            the context
	 * @return the built GraphicalView
	 */
	@Override
	public final GraphicalView execute(Context context) {
		DefaultRenderer renderer = buildCategoryRenderer(colors);
		GraphicalView chart = ChartFactory.getPieChartView(context,
				buildCategoryDataset(title, categories, values), renderer);
		return chart;
	}

}
