开发者

Loop through a series points in JFreechart

Is it possible to loop through a the points belonging to a series in JFreechart? Tha开发者_开发技巧nks


Yes, for example a XYSeriesColleciton with one XYSeries that including simple Numbers:
Here is the code:

XYSeriesCollection dataSet0 = (XYSeriesCollection) plot.getDataset(0);
XYSeries series0 = dataSet0.getSeries(0);
for (Object i : series0.getItems()) {
  XYDataItem item = (XYDataItem) i;
  double x = item.getXValue();
  double y = item.getYValue();
}


You can loop through the columns and the rows in any given plot, but as trashgod commented: you should do the looping in your data model.

If you insist on looping through the points you can do this in two ways:

  • Loop through the number of rows/columns and get the value for a given index of the row/column
  • Loop through the keys of the rows/columns and get the value for a given keypair of row/column

This is done on the dataset for the given series. You should be able to use the following methods to achieve that:

int getColumnCount(); // Returns the number of columns in the table.
int getRowCount(); // Returns the number of rows in the table.

java.util.List getColumnKeys(); // Returns the column keys.
java.util.List getRowKeys(); // Returns the row keys.

java.lang.Number getValue(java.lang.Comparable rowKey, java.lang.Comparable columnKey); // Returns the value for a pair of keys.

For more info consult the JFreeChart documentation here, or go buy the developer manual for in-depth explainations of the classes.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜