2 * Copyright (C) 2009 - 2012 SC 4ViewSoft SRL
\r
4 * Licensed under the Apache License, Version 2.0 (the "License");
\r
5 * you may not use this file except in compliance with the License.
\r
6 * You may obtain a copy of the License at
\r
8 * http://www.apache.org/licenses/LICENSE-2.0
\r
10 * Unless required by applicable law or agreed to in writing, software
\r
11 * distributed under the License is distributed on an "AS IS" BASIS,
\r
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
13 * See the License for the specific language governing permissions and
\r
14 * limitations under the License.
\r
16 package org.achartengine.model;
\r
18 import java.io.Serializable;
\r
19 import java.util.ArrayList;
\r
20 import java.util.List;
\r
23 * A series for the category charts like the pie ones.
\r
25 public class CategorySeries implements Serializable {
\r
26 /** The series title. */
\r
27 private String mTitle;
\r
28 /** The series categories. */
\r
29 private List<String> mCategories = new ArrayList<String>();
\r
30 /** The series values. */
\r
31 private List<Double> mValues = new ArrayList<Double>();
\r
34 * Builds a new category series.
\r
36 * @param title the series title
\r
38 public CategorySeries(String title) {
\r
43 * Returns the series title.
\r
45 * @return the series title
\r
47 public String getTitle() {
\r
52 * Adds a new value to the series
\r
54 * @param value the new value
\r
56 public synchronized void add(double value) {
\r
57 add(mCategories.size() + "", value);
\r
61 * Adds a new value to the series.
\r
63 * @param category the category
\r
64 * @param value the new value
\r
66 public synchronized void add(String category, double value) {
\r
67 mCategories.add(category);
\r
72 * Replaces the value at the specific index in the series.
\r
74 * @param index the index in the series
\r
75 * @param category the category
\r
76 * @param value the new value
\r
78 public synchronized void set(int index, String category, double value) {
\r
79 mCategories.set(index, category);
\r
80 mValues.set(index, value);
\r
84 * Removes an existing value from the series.
\r
86 * @param index the index in the series of the value to remove
\r
88 public synchronized void remove(int index) {
\r
89 mCategories.remove(index);
\r
90 mValues.remove(index);
\r
94 * Removes all the existing values from the series.
\r
96 public synchronized void clear() {
\r
97 mCategories.clear();
\r
102 * Returns the value at the specified index.
\r
104 * @param index the index
\r
105 * @return the value at the index
\r
107 public synchronized double getValue(int index) {
\r
108 return mValues.get(index);
\r
112 * Returns the category name at the specified index.
\r
114 * @param index the index
\r
115 * @return the category name at the index
\r
117 public synchronized String getCategory(int index) {
\r
118 return mCategories.get(index);
\r
122 * Returns the series item count.
\r
124 * @return the series item count
\r
126 public synchronized int getItemCount() {
\r
127 return mCategories.size();
\r
131 * Transforms the category series to an XY series.
\r
133 * @return the XY series
\r
135 public XYSeries toXYSeries() {
\r
136 XYSeries xySeries = new XYSeries(mTitle);
\r
138 for (double value : mValues) {
\r
139 xySeries.add(++k, value);
\r