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.util.ArrayList;
\r
19 import java.util.List;
\r
21 * A series for the range category charts like the range bar.
\r
23 public class RangeCategorySeries extends CategorySeries {
\r
24 /** The series values. */
\r
25 private List<Double> mMaxValues = new ArrayList<Double>();
\r
27 * Builds a new category series.
\r
29 * @param title the series title
\r
31 public RangeCategorySeries(String title) {
\r
35 * Adds new values to the series
\r
37 * @param minValue the new minimum value
\r
38 * @param maxValue the new maximum value
\r
40 public synchronized void add(double minValue, double maxValue) {
\r
41 super.add(minValue);
\r
42 mMaxValues.add(maxValue);
\r
46 * Adds new values to the series.
\r
48 * @param category the category
\r
49 * @param minValue the new minimum value
\r
50 * @param maxValue the new maximum value
\r
52 public synchronized void add(String category, double minValue, double maxValue) {
\r
53 super.add(category, minValue);
\r
54 mMaxValues.add(maxValue);
\r
58 * Removes existing values from the series.
\r
60 * @param index the index in the series of the values to remove
\r
62 public synchronized void remove(int index) {
\r
63 super.remove(index);
\r
64 mMaxValues.remove(index);
\r
68 * Removes all the existing values from the series.
\r
70 public synchronized void clear() {
\r
76 * Returns the minimum value at the specified index.
\r
78 * @param index the index
\r
79 * @return the minimum value at the index
\r
81 public double getMinimumValue(int index) {
\r
82 return getValue(index);
\r
86 * Returns the maximum value at the specified index.
\r
88 * @param index the index
\r
89 * @return the maximum value at the index
\r
91 public double getMaximumValue(int index) {
\r
92 return mMaxValues.get(index);
\r
96 * Transforms the range category series to an XY series.
\r
98 * @return the XY series
\r
100 public XYSeries toXYSeries() {
\r
101 XYSeries xySeries = new XYSeries(getTitle());
\r
102 int length = getItemCount();
\r
103 for (int k = 0; k < length; k++) {
\r
104 xySeries.add(k + 1, getMinimumValue(k));
\r
105 // the new fast XYSeries implementation doesn't allow 2 values at the same X,
\r
106 // so I had to do a hack until I find a better solution
\r
107 xySeries.add(k + 1.000001, getMaximumValue(k));
\r