我在程序中使用了jfree图表。我使用DefaultCategoryDataset
来保存我想要在我的图表中显示的数据。现在我想写DefaultCategoryDataset
值包括列,行和值的列表。
谁知道我怎么能这样做?
frame = new JFrame();
frame.setBounds(50, 50, 1135, 1029);
DefaultCategoryDataset dataSet = new DefaultCategoryDataset();
for (int i = 0; i < observedEWMAs.size(); i++) {
dataSet.addValue(observedEWMAs.get(i), "observed" + title,
((Integer) (i + 1)).toString());
//here i want to write data set fo file
答案 0 :(得分:1)
使用DefaultCategoryDataset
中定义的BarChartDemo1
,here,以下代码生成预期输出:
代码:
for (int r = 0; r < dataset.getRowCount(); r++) {
String series = (String) dataset.getRowKey(r);
for (int c = 0; c < dataset.getColumnCount(); c++) {
System.out.println(series
+ ", " + dataset.getColumnKey(c)
+ ", " + dataset.getValue(r, c));
}
}
控制台:
First, Category 1, 1.0 First, Category 2, 4.0 First, Category 3, 3.0 First, Category 4, 5.0 First, Category 5, 5.0 Second, Category 1, 5.0 Second, Category 2, 7.0 Second, Category 3, 6.0 Second, Category 4, 8.0 Second, Category 5, 4.0 Third, Category 1, 4.0 Third, Category 2, 3.0 Third, Category 3, 2.0 Third, Category 4, 3.0 Third, Category 5, 6.0