X-Git-Url: https://git.gag.com/?a=blobdiff_plain;f=android-libraries%2Fachartengine%2Fsrc%2Forg%2Fachartengine%2Fmodel%2FCategorySeries.java;fp=android-libraries%2Fachartengine%2Fsrc%2Forg%2Fachartengine%2Fmodel%2FCategorySeries.java;h=ae31c7dda1fdac02b14f12387f43ff742241a8c1;hb=dfe153139b917cc91dddc1efa0298d4204616462;hp=0000000000000000000000000000000000000000;hpb=a2fe0ba2c348102bb0c6486b201be097523c2c9a;p=debian%2Fopenrocket diff --git a/android-libraries/achartengine/src/org/achartengine/model/CategorySeries.java b/android-libraries/achartengine/src/org/achartengine/model/CategorySeries.java new file mode 100644 index 00000000..ae31c7dd --- /dev/null +++ b/android-libraries/achartengine/src/org/achartengine/model/CategorySeries.java @@ -0,0 +1,143 @@ +/** + * Copyright (C) 2009 - 2012 SC 4ViewSoft SRL + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.achartengine.model; + +import java.io.Serializable; +import java.util.ArrayList; +import java.util.List; + +/** + * A series for the category charts like the pie ones. + */ +public class CategorySeries implements Serializable { + /** The series title. */ + private String mTitle; + /** The series categories. */ + private List mCategories = new ArrayList(); + /** The series values. */ + private List mValues = new ArrayList(); + + /** + * Builds a new category series. + * + * @param title the series title + */ + public CategorySeries(String title) { + mTitle = title; + } + + /** + * Returns the series title. + * + * @return the series title + */ + public String getTitle() { + return mTitle; + } + + /** + * Adds a new value to the series + * + * @param value the new value + */ + public synchronized void add(double value) { + add(mCategories.size() + "", value); + } + + /** + * Adds a new value to the series. + * + * @param category the category + * @param value the new value + */ + public synchronized void add(String category, double value) { + mCategories.add(category); + mValues.add(value); + } + + /** + * Replaces the value at the specific index in the series. + * + * @param index the index in the series + * @param category the category + * @param value the new value + */ + public synchronized void set(int index, String category, double value) { + mCategories.set(index, category); + mValues.set(index, value); + } + + /** + * Removes an existing value from the series. + * + * @param index the index in the series of the value to remove + */ + public synchronized void remove(int index) { + mCategories.remove(index); + mValues.remove(index); + } + + /** + * Removes all the existing values from the series. + */ + public synchronized void clear() { + mCategories.clear(); + mValues.clear(); + } + + /** + * Returns the value at the specified index. + * + * @param index the index + * @return the value at the index + */ + public synchronized double getValue(int index) { + return mValues.get(index); + } + + /** + * Returns the category name at the specified index. + * + * @param index the index + * @return the category name at the index + */ + public synchronized String getCategory(int index) { + return mCategories.get(index); + } + + /** + * Returns the series item count. + * + * @return the series item count + */ + public synchronized int getItemCount() { + return mCategories.size(); + } + + /** + * Transforms the category series to an XY series. + * + * @return the XY series + */ + public XYSeries toXYSeries() { + XYSeries xySeries = new XYSeries(mTitle); + int k = 0; + for (double value : mValues) { + xySeries.add(++k, value); + } + return xySeries; + } +}