How can I get series by name
How can I get series by name
Hi, I use XYSeriesCollection and how can I get a serie from dataset by serie's name ???
-
- JFreeChart Project Leader
- Posts: 11734
- Joined: Fri Mar 14, 2003 10:29 am
- antibot: No, of course not.
- Contact:
It looks as though you can only iterate through the collection, and call getSeriesKey(int) for each series, then if you get a matching key call getSeries(int).
I propose the following method (to add in XYSeriesCollection) to fill that gap:
Let me know if you spot a problem with it.
I propose the following method (to add in XYSeriesCollection) to fill that gap:
Code: Select all
/**
* Returns a series from the collection.
*
* @param key the key (<code>null</code> not permitted).
*
* @return The series with the specified key.
*
* @throws UnknownKeyException if <code>key</code> is not found in the
* collection.
*
* @since 1.0.9
*/
public XYSeries getSeries(Comparable key) {
if (key == null) {
throw new IllegalArgumentException("Null 'key' argument.");
}
Iterator iterator = this.data.iterator();
while (iterator.hasNext()) {
XYSeries series = (XYSeries) iterator.next();
if (key.equals(series.getKey())) {
return series;
}
}
throw new UnknownKeyException("Key not found: " + key);
}
David Gilbert
JFreeChart Project Leader
Read my blog
Support JFree via the Github sponsorship program
JFreeChart Project Leader

