java JFreeChart 如何获取时间序列图表上显示的数据点
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10305673/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
JFreeChart How to get data points displayed on a Time series chart
提问by fred basset
I just want to get the data points on my chart to show up, how do I do this? The plot shows up fine as a line plot but I want small markers for each individual data point.
我只想让图表上的数据点显示出来,我该怎么做?该图显示为线图,但我想要每个单独的数据点的小标记。
JFreeChart portion of the app is:
应用程序的 JFreeChart 部分是:
private XYDataset createDataset() {
final TimeSeries inclinometerAngles = new TimeSeries(TimeUnit.SECONDS);
// Add all data from the map to the dataset
final Set<Date> keys = data.keySet();
for (Date date : keys) {
Record r = data.get(date);
if (r.mcInclinometerAngle != null) {
inclinometerAngles.add(new Second(date), r.mcInclinometerAngle);
}
}
final TimeSeriesCollection dataset = new TimeSeriesCollection();
dataset.addSeries(inclinometerAngles);
return dataset;
}
private void setupGraphics() {
final XYDataset dataset = createDataset();
final JFreeChart chart = createChart(dataset);
final ChartPanel chartPanel = new ChartPanel(chart);
chartPanel.setPreferredSize(new java.awt.Dimension(500, 270));
chartPanel.setMouseZoomable(true, false);
setContentPane(chartPanel);
}
private JFreeChart createChart(final XYDataset dataset) {
final JFreeChart chart = ChartFactory.createTimeSeriesChart(
"Tracker Analysis",
"Date",
"Value",
dataset,
true,
true,
false
);
final XYPlot plot = chart.getXYPlot();
XYItemRenderer renderer = plot.getRenderer();
final StandardXYToolTipGenerator g = new StandardXYToolTipGenerator(
StandardXYToolTipGenerator.DEFAULT_TOOL_TIP_FORMAT,
new SimpleDateFormat(), new DecimalFormat("0.00")
);
renderer.setToolTipGenerator(g);
renderer.setItemLabelsVisible(true);
return chart;
}
回答by trashgod
JFreeChart.createTimeSeriesChart()
uses an XYLineAndShapeRenderer
, so start by making the shapes visible.
JFreeChart.createTimeSeriesChart()
使用XYLineAndShapeRenderer
,因此首先使形状可见。
renderer.setSeriesShapesVisible(true);
This related exampleillustrates a few of the other methods that affect the appearance.
这个相关的例子说明了一些影响外观的其他方法。