我要求将时间序列数据显示为分层条形图。是否可以使用JFreeChart?任何指点都会很有帮助。
数据将是一个列表:(TS,X1,X2),其中我必须为给定的时间戳(TS)绘制X1,而X2基本上用作X1的给定值的标签。
编辑:同样,对于相同的TS,可能存在不同的X1值。其思想是将所有这些X1值表示为针对相同TS的分层条形图。
下面是我想要的一个例子:

。
(因此,我将在X轴上使用TS,而不是类别)
发布于 2012-06-10 22:12:26
这听起来像是您想要一个BarChart (x轴由时间确定),并用它们的值标记条形图。您不需要为标签添加新的数据系列,而是修改绘图的呈现。
下面是一个简单的例子:
public class LabelledBarChartTest {
public static void main(String[] args) {
JFrame frame = new JFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
DefaultCategoryDataset dataset = new DefaultCategoryDataset();
dataset.addValue(10.0, "Series", new Integer(2010));
dataset.addValue(20.0, "Series", new Integer(2011));
dataset.addValue(30.0, "Series", new Integer(2012));
JFreeChart chart = ChartFactory.createBarChart(null,null,null,dataset,
PlotOrientation.VERTICAL,true,true,false);
CategoryPlot plot = (CategoryPlot) chart.getPlot();
CategoryItemRenderer renderer = plot.getRenderer();
// label the points
NumberFormat format = NumberFormat.getNumberInstance();
format.setMaximumFractionDigits(2);
CategoryItemLabelGenerator generator = new StandardCategoryItemLabelGenerator(
StandardXYItemLabelGenerator.DEFAULT_ITEM_LABEL_FORMAT, format, format);
renderer.setBaseItemLabelGenerator(generator);
renderer.setBaseItemLabelsVisible(true);
frame.setContentPane(new ChartPanel(chart));
frame.pack();
frame.setVisible(true);
}
}值得表扬的地方--我从这个example得到了标签示例。
https://stackoverflow.com/questions/10952415
复制相似问题